You need to use CREATE command to create a new user with password in MySQL 8. Let us check the version
mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.14 sec)
The syntax is as follows to create a new user with password
CREATE USER 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';
The following is the syntax to grant all privileges to the created user
GRANT ALL ON *.* TO 'yourUserName'@'localhost';
Now flush the privileges using flush command
flush privileges;
Let us create a new user with the help of the above syntax. The query is as follows
mysql> use MySQL; Database changed mysql> CREATE USER 'James'@'localhost' IDENTIFIED BY 'James123456'; Query OK, 0 rows affected (0.21 sec)
The following is the query to grant all privileges to the newly created user
mysql> GRANT ALL ON *.* TO 'James'@'localhost'; Query OK, 0 rows affected (0.18 sec)
Let us check the user has been created or not
mysql> select user from MySQL.user;
The following is the output displaying the new user we created above
+------------------+ | user | +------------------+ | Bob | | Manish | | User2 | | mysql.infoschema | | mysql.session | | mysql.sys | | root | | @UserName@ | | Adam Smith | | James | | John | | John Doe | | User1 | | am | | hbstudent | | mysql.infoschema | | mysql.session | +------------------+ 17 rows in set (0.00 sec)
Look at the sample output, the user James has been created successfully. Now flush the privileges using a flush command. The query is as follows
mysql> flush privileges; Query OK, 0 rows affected (0.04 sec)