You are on page 1of 2

Syntax:

CREATE USER user_specification


[, user_specification] ...

user_specification:
user
[
IDENTIFIED BY [PASSWORD] 'password'
| IDENTIFIED WITH auth_plugin [AS 'auth_string']
]

The CREATE USER statement creates new MySQL accounts. To use it, you
must have the global CREATE USER privilege or the INSERT privilege for
the mysql database. For each account, CREATE USER creates a new row in
the mysql.user table and assigns the account no privileges. An error
occurs if the account already exists.

Each account name uses the format described in


https://mariadb.com/kb/en/create-user#account-names. For example:

CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';

If you specify only the user name part of the account name, a host name
part of '%' is used.

The user specification may indicate how the user should authenticate
when connecting to the server:

o To enable the user to connect with no password (which is insecure),


include no IDENTIFIED BY clause:

CREATE USER 'jeffrey'@'localhost';

In this case, the account uses built-in authentication and clients


must provide no password.

o To assign a password, use IDENTIFIED BY with the literal plaintext


password value:

CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';

The account uses built-in authentication and clients must match the
given password.

o To avoid specifying the plaintext password if you know its hash value
(the value that PASSWORD() would return for the password), specify
the hash value preceded by the keyword PASSWORD:

CREATE USER 'jeffrey'@'localhost'


IDENTIFIED BY PASSWORD '*90E462C37378CED12064BB3388827D2BA3A9B689';

The account uses built-in authentication and clients must match the
given password.

o To authenticate the account using a specific authentication plugin,


use IDENTIFIED WITH, where auth_plugin is the plugin name. It can be
an unquoted name or a quoted string literal. 'auth_string' is an
optional quoted string literal to pass to the plugin. The plugin
interprets the meaning of the string, so its format is plugin
specific. Consult the documentation for a given plugin for
information about the authentication string values it accepts.

CREATE USER 'jeffrey'@'localhost'


IDENTIFIED WITH my_auth_plugin;
For connections that use this account, the server invokes the named
plugin and clients must provide credentials as required for the
authentication method that the plugin implements. If the server
cannot find the plugin, either at account-creation time or connect
time, an error occurs. IDENTIFIED WITH can be used as of MySQL 5.5.7.

The IDENTIFIED BY and IDENTIFIED WITH clauses are mutually exclusive,


so at most one of them can be specified for a given user.

For additional information about setting passwords, see


https://mariadb.com/kb/en/create-user/.

URL: https://mariadb.com/kb/en/create-user/

You might also like