Creating user accounts in MySQL

MySQL user names can be up to 16 characters long.

Here are the queries for creating user accounts in MySQL:

Create user with no password

mysql> CREATE USER 'newuser'@'localhost';

Create user with password test123

mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'test123';

If we know the hash value of the password returned by PASSWORD() function then use below

mysql> CREATE USER 'newuser'@'localhost'
IDENTIFIED BY PASSWORD '*90E462C37378CED12064BB3388827D2BA3A9B689';

MySQL stores accounts in the user table of the mysql database. So we can directly insert a new record in the table to add a new user account with password as below:

mysql> INSERT INTO mysql.user (Host,User,Password)  VALUES('localhost','newuser',PASSWORD('newpassword'));
mysql> FLUSH PRIVILEGES;

Create anonymous user

CREATE USER ''@'localhost';

Leave a Comment

Back to top