Changes

Jump to: navigation, search

MySQL Users and Security

1,230 bytes added, 13:53, 29 October 2007
Creating a New MySQL User
<pre>
CREATE USER 'johnB'@'localhost' IDENTIFIED BY 'yrthujoi';
</pre>
 
We can verify the new user has been added by querying the user table:
 
<pre>
mysql> SELECT host, user, password FROM user WHERE user='johnB';
+-----------+-------+------------------+
| host | user | password |
+-----------+-------+------------------+
| localhost | johnB | 2c7ed55a48a81f36 |
+-----------+-------+------------------+
1 row in set (0.00 sec)
</pre>
 
As we can see, the password is not stored in plain text in the user table and has instead been encrypted by MySQL so that it cannot be obtained simply by performing a SELECT query on the table.
 
You may have noted that we specified that johnB could only connect from 'localhost', in other words the same system on which the MySQL server is running. This means that if johnB tries to connect to the MySQL server from a client running on a remote system, the connection will fail. In order to create an account which can connect from a particular host, simply specify the host name or IP address in place of the ''localhost'' in the above example. Alternatively, to allow a user to connect to the MySQL server from any remote host, simply use the '%' character in place of the host name:
 
<pre>
CREATE USER 'johnB'@'%' IDENTIFIED BY 'yrthujoi';
</pre>

Navigation menu