CREATE USER '[username]'@'[userhost]' INDENTIFIED BY '[userpassword]';
CREATE USER '[username]' INDENTIFIED BY '[userpassword]';
CREATE USER 'kennyl'@'localhost' INDENTIFIED BY 'mypassword';
Users are stored in the user
table of the mysql
database... synical I know. The table has two keys; user
and host
. So it's possible to have multiple copies of the same username from different hosts. For example: 'kennyl'@'Remington'
and 'kennyl'@'magnum'
are two different users. Even though the user names are identical, the host is different, and since user
has a joint key, they are different.
However, you don't really have to have a host. One could simply have a username and no host. MySQL will record the host name as %
. So technically there is a host, but no one would know... unless they peeked in the user table.
By the way - user
and host
are always put in quotes:'kennyl'@'localhost'
. Single, double... it doen't matter.
To create a user one must indicate the user, the host and the password or just the user and password. Syntax is like this:
... or just ...
... and the server will record the host name as %
Example:
When working interactivly in the MySQL client everything is recorded. It goes in a file called .mysql_history
in the users home directory. If you create a user the exact syntax goes in this file including the password in plain text. Personnaly, I delete this file when I log out.
NOTE:
ADDUSER syntax in the mysql manual.