MySQL create a user (CREATE USER)

In the daily management of MySQL and practice, in order to avoid false malicious user to use the root account control database, often you need to create a series of accounts with appropriate permissions, should be no or little as possible with the root account login system, in order to ensure secure access to data.

 

Create a user

You can use CREATE USER statement to create one or more MySQL accounts, and set the password.

Syntax:

CREATE USER <username> [IDENTIFIED] BY [PASSWORD] <password>

Syntax is as follows:

1) <user name>

Specifies to create a user account in the format 'user_name' @ 'host_name'. Here user_nameis a user name, host_namethe host name, that is where the name of the host when users connect MySQL. If in the process of creation, only the given name of the user account, but did not specify a host name, the host name defaults to "%", said a group of hosts.

2) PASSWORD

Optionally, to specify the password hash, that is, if plain text password is set, you need to ignore PASSWORDkeyword; if do not want to set a password in clear text, and know the PASSWORD () function returns the hash value to the password, you can set password statement this hash value is specified, but the need to add keywords PASSWORD.

3) IDENTIFIED BY clause

Is used to specify the user password corresponding to the account, if the user account without a password, this clause can be omitted.

4) <password>

Specifies the user account password, in IDENTIFIED BYkeywords, or PASSWOEDafter the keyword. Given plaintext password value may be only letters and numbers, or may be a hash value by PASSWORD () function is obtained.

Use CREATE USER statement should note the following:

  • If you do not specify a CREATE USER statement using the user's password, then MySQL can not allow the user to log in with a password, but from a security point of view, this is not recommended.
  • Use CREATE USER statement must have INSERT in MySQL MySQL database privileges or global CREATE USER privilege.
  • After you create a user account using the CREATE USER statement adds a new record in the user table system itself MySQL database. If you created an account already exists, the statement error occurs when executed.
  • Users with permission of newly created small. They can log on MySQL, allowing only operation does not require permissions, such as using the SHOW statement to query a list of all the storage engine and character set and so on.

If two users have the same user name and a different host name, MySQL will see them as a different user, and allows the assignment of a different set of permissions for both users.

[Example 1] create a user CREATE USER, the user name is james, password is tiger, the host is localhost. As shown in SQL statements and execution of the following forms.

  mysql> CREATE USER 'james'@'localhost'      -> IDENTIFIED BY 'tiger';  Query OK, 0 rows affected (0.12 sec)

In the Windows command-line tool, user and password tiger james database server to log the newly created, as shown below.

  C:UsersUSER>mysql -h localhost -u james -p  Enter password: *****  Welcome to the
Published 44 original articles · won praise 1 · views 10000 +

Guess you like

Origin blog.csdn.net/mysqlsd/article/details/103474780