This page gives a description of simple tasks to do with managing user accounts on MySQL.
To create a user on MySQL, log in as root and use
mysql> CREATE USER 'name';
name is the user name. This creates a
'name'@'%', where the percent sign indicates the
user can log in from any host. You can check the user as follows:
use mysql; select User, Host from user;
This selects mysql's own database and prints a list of users and the hosts they can log in from.
The newly created user can log in to MySQL without a password, by typing
$ mysql -u name
To create an account with a password, use
mysql> CREATE USER 'name' IDENTIFIED BY 'passwd';
passwd is the password. Then the user can log in using
mysql -u name -p
MySQL starts and prompts the user for the password.
To add or change the password for a user, log in as root and use
mysql> SET PASSWORD FOR 'name' = PASSWORD('passwd');
name is the user's name, and
the user's password in plain text. This operates
'name'@'%', the host is the wildcard
mysql> SET PASSWORD = PASSWORD('passwd');
sets the password for the account that you are currently logged in with.
To find out what your current user name is, similar to
whoami on Unix, use
mysql> select current_user();
mysql> select user();
The second version gives the actual IP whereas the first one gives % in the host column.
To change the user name of an account, log in as root and use
mysql> rename user old_name to new_name;
old_name is the current user name, and
new_name is the name which you want to change to.
To delete a user, use
mysql> DROP USER name;