How to Create MySQL Users Accounts and Grant Privileges in MySQL 8.0

We will learn how to add new users to the MySQL database server. MySQL provides very flexible and granular user management options.

Follow these steps to add users to MySQL database server and assign access rights:

Step 1 : Open the MySQL shell with the following command.

sudo mysql

Step 2 : From the MySQL shell, use the following command to add a new user to MySQL:

mysql> create user 'admin'@'localhost' identified by 'password';

Step 3 : You can check the user account with the following command:

mysql> select user, authentication_string, plugin, host from mysql.user where user = 'admin';

Step 4 : Next, add some privileges to this user account

mysql> grant all privileges on *.* to 'admin'@'localhost' with grant option;

Step 5 : Verify the privileges for the account as follows

mysql> show grants for 'admin'@'localhost';

Step 6 : Finally, exit the MySQL shell and try to log in with the new user account. You should log in successfully:

mysql> exit
    mysql -u admin -p

Add Comment