Mysql Create User Statement

MySQL: CREATE USER statement

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

Description

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

Syntax

The syntax for the CREATE USER statement in MySQL 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 MySQL using the CREATE USER statement.

For example:

CREATE USER
  'ao'@'localhost' IDENTIFIED BY 'autumn';

In this example, the CREATE USER statement would create a new user called ao in the MySQL database whose password is 'autumn'.

Create more than one user

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

For example:

CREATE USER
  'ao'@'localhost' IDENTIFIED BY 'autumn',
  'andersonk'@'localhost' IDENTIFIED BY 'summer';

This CREATE USER example would create two users in MySQL. The first user would be called ao with a password of 'autumn', and the second user would be called andersonk with a password of 'summer'.

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
  'ao'@'localhost' IDENTIFIED BY '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19';

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