totn MariaDB

MariaDB: CREATE USER statement

This MariaDB tutorial explains how to use the MariaDB CREATE USER statement with syntax and examples.

Description

The CREATE USER statement creates a database account that allows you to log into the MariaDB database.

Syntax

The syntax for the CREATE USER statement in MariaDB is:

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

Parameters or Arguments

user_name
The name of the database account that you wish to create.
PASSWORD
Optional. Whether you specify it or not, the CREATE USER statement will behave the same.
password_value
The password to assign to user_name.

Example

Let's look at how to create a user in MariaDB using the CREATE USER statement.

For example:

CREATE USER
  'techonthenet'@'localhost' IDENTIFIED BY 'firstpassword';

In this example, the CREATE USER statement would create a new user called techonthenet in the MariaDB database whose password is 'firstpassword'.

Create more than one user

How can you create more than one user at a time in MariaDB? You can use the CREATE USER statement to create multiple users by comma separating each user/password combinations.

For example:

CREATE USER
  'techonthenet'@'localhost' IDENTIFIED BY 'firstpassword',
  'checkyourmath'@'localhost' IDENTIFIED BY 'secondpassword';

This CREATE USER example would create two users in MariaDB. The first user would be called techonthenet with a password of 'firstpassword', and the second user would be called checkyourmath with a password of 'secondpassword'.

Using Hash value for password

The examples above displayed a plaintext password. You also have the option of providing the hash value for the password (see the PASSWORD function).

For example:

CREATE USER
  'techonthenet'@'localhost' IDENTIFIED BY '*BAC7C920F2507B848358495F25F1B509C0C5C279';

This CREATE USER example would create a new user called techonthenet in the MariaDB database with a hash value of the password.