MySQL: CREATE USER statement

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL create user statement

In this guide, we will explain 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 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_nameThe name of the database account that you wish to create.PASSWORDOptional. Whether you specify it or not, the CREATE USER statement will behave the same.password_valueThe password to assign to user_name.

Example

Let’s look at how to create a user using the CREATE USER statement.

For example:

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

In this example, the CREATE USER statement would create a new user called smithj 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 combination.

For example:

CREATE USER
  'smithj'@'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 smithj with a password of ‘autumn’, and the second user would be called Anderson 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
  'smithj'@'localhost' IDENTIFIED BY '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19';

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

Next Topic : Click Here

This Post Has One Comment

Leave a Reply