MySQL MySQL authorized to create a user to create user and authorization

A. Create a user

command:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

Description:

  • username: You will create a username
  • host: Specifies the host on which the user can log in, if it is locally available to the user localhost, if you want the user can log in from any remote host , you can use wildcards%
  • password: the user's login password, the password can be empty, if empty then the user can log in without a password server

example:

CREATE USER '用户名'@'localhost' IDENTIFIED BY '123456';
CREATE USER '用户名'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER '用户名'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';

II. Authorization:

command:

GRANT privileges ON databasename.tablename TO 'username'@'host'

Description:

  • privileges: the user's operating authority, such as SELECT, INSERT, UPDATEand so on, if you want to grant permission to the use of theALL
  • databasename: database name
  • tablename: Table name, if you want to grant the user is available for all database tables and corresponding operating authority *said that if*.*

example:

GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
GRANT ALL ON maindataplus.* TO 'pig'@'%';

note:

Authorized users can not use the above command to other authorized users, if you want the user may be authorized, with the following command:

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

III. Setup and change the user password

command:

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');

If the user is currently logged on with:

SET PASSWORD = PASSWORD("newpassword");

example:

SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");

IV. Revoke user privileges

command:

REVOKE privilege ON databasename.tablename FROM 'username'@'host';

Description:

privilege, databasename, tablename: with the authorization section

example:

REVOKE SELECT ON *.* FROM 'pig'@'%';

note:

If you are a user 'pig'@'%'authorization is such that when (or similar): GRANT SELECT ON test.user TO 'pig'@'%'is used in REVOKE SELECT ON *.* FROM 'pig'@'%';order that the user does not withdraw the test database user table SELECT operation. Conversely, if the authorization using GRANT SELECT ON *.* TO 'pig'@'%';the REVOKE SELECT ON test.user FROM 'pig'@'%';command can not revoke the user to test the database user table Selectprivileges.

Specific information can use the command SHOW GRANTS FOR 'pig'@'%'; to view.

V. delete users

command:

DROP USER 'username'@'host';

A. Create a user

command:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

Description:

  • username: You will create a username
  • host: Specifies the host on which the user can log in, if it is locally available to the user localhost, if you want the user can log in from any remote host , you can use wildcards%
  • password: the user's login password, the password can be empty, if empty then the user can log in without a password server

example:

CREATE USER '用户名'@'localhost' IDENTIFIED BY '123456';
CREATE USER '用户名'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER '用户名'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';

II. Authorization:

command:

GRANT privileges ON databasename.tablename TO 'username'@'host'

Description:

  • privileges: the user's operating authority, such as SELECT, INSERT, UPDATEand so on, if you want to grant permission to the use of theALL
  • databasename: database name
  • tablename: Table name, if you want to grant the user is available for all database tables and corresponding operating authority *said that if*.*

example:

GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
GRANT ALL ON maindataplus.* TO 'pig'@'%';

note:

Authorized users can not use the above command to other authorized users, if you want the user may be authorized, with the following command:

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

III. Setup and change the user password

command:

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');

If the user is currently logged on with:

SET PASSWORD = PASSWORD("newpassword");

example:

SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");

IV. Revoke user privileges

command:

REVOKE privilege ON databasename.tablename FROM 'username'@'host';

Description:

privilege, databasename, tablename: with the authorization section

example:

REVOKE SELECT ON *.* FROM 'pig'@'%';

note:

If you are a user 'pig'@'%'authorization is such that when (or similar): GRANT SELECT ON test.user TO 'pig'@'%'is used in REVOKE SELECT ON *.* FROM 'pig'@'%';order that the user does not withdraw the test database user table SELECT operation. Conversely, if the authorization using GRANT SELECT ON *.* TO 'pig'@'%';the REVOKE SELECT ON test.user FROM 'pig'@'%';command can not revoke the user to test the database user table Selectprivileges.

Specific information can use the command SHOW GRANTS FOR 'pig'@'%'; to view.

V. delete users

command:

DROP USER 'username'@'host';

Guess you like

Origin www.cnblogs.com/crave/p/11412130.html