MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB - CREATE USER



The MariaDB CREATE USER statement is used to create a database account that allows the specified user to log into the MariaDB database.

Syntax

The syntax of using CREATE USER statement in MariaDB is given below:

CREATE USER
  user_name IDENTIFIED BY [PASSWORD] 'password_value';

Parameters

user_name Required. Specify the name of the database account that need to be created.
PASSWORD Optional. Whether specified or not, the CREATE USER statement behaves in the same way.
password_value Required. Specify the password to assign to user_name.

Example: Create a user

In the example below, the CREATE USER statement is used to create a new user called john in the MariaDB database with password 'password1'.

CREATE USER
  'john'@'localhost' IDENTIFIED BY 'password1';

Example: Create more than one user

In the example below, two user is created in the MariaDB database. First is john with password 'password1'. Second is marry with password 'password2'.

CREATE USER
  'john'@'localhost' IDENTIFIED BY 'password1',
  'marry'@'localhost' IDENTIFIED BY 'password2';

Example: Using Hash value for password

In the example above, plaintext password is used. The password can be provided using its hash value (see the PASSWORD() function). For example - to create a new user called john with password 'password1', the following statement can be used.

CREATE USER
  'john'@'localhost' IDENTIFIED BY '*668425423DB5193AF921380129F465A6425216D0';

OR

CREATE USER
  'john'@'localhost' IDENTIFIED BY PASSWORD('password1');

5