Create Mysql User
Create Mysql User
Login to MySQL
First well login to the MySQL server from the command line with the following command:
mysql -u root -p
In this case, Ive specified the user with the flag, and then used the flag so MySQL prompts for a
password. Enter your current password to complete the login.
If you need to change your root (or any other) password in the database, then follow this tutorial on
changing a password for MySQL via the command line.
You should now be at a MySQL prompt that looks very similar to this:
mysql>
Create MySQL User
Well create a user with the name testuser , and the password test123test!.
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'test123test!';
Thats it, congratulations! In just one command youve created your first MySQL user. However,
this user wont be able to do anything with MySQL until they are granted additional privileges. In
fact, they wont even be able to login without additional permissions.
View a List of MySQL Users
Viewing a full list of MySQL users, including the host theyre associated with, can be done with the
following select statement:
SELECT User,Host FROM mysql.user;
If you need to change your root (or any other) password in the database, then follow this tutorial on
changing a password for MySQL via the command line.
You should now be at a MySQL prompt that looks very similar to this:
mysql>
If you havent yet created a MySQL user, please refer to our tutorial on creating a MySQL user.
View a List of MySQL Users
Viewing a full list of MySQL users, including the host theyre associated with, can be done with the
following select statement:
SELECT User,Host FROM mysql.user;
Remove a MySQL User
To remove a user from MySQL, we again use the command.
It only takes one simple command to delete a user in MySQL, but BEWARE; dropping a user can
not be undone! The command is as follows:
DROP USER 'testuser'@'localhost';
If a user of the name does not exist, then youll receive this error:
ERROR 1396 (HY000): Operation DROP USER failed for
'testuser'@'localhost'
Refer to the section above if you receive the above error, and double check the username and host.