One, create the user:
Command: CREATE USER ' username ' @ ' host ' identified by ' password ';
Description: Username-user name,
Host-Specifies the host on which the user can log on, and if localhost is available to the local user, you can use the wildcard% if you want the user to be able to log on from any remote host.
Password-the user login password, the password can be empty, if it is empty, the user can not require a password to log on to the server.
Example: CREATE USER ' admin_user ' @ ' localhost ' identified by ' 123456 ';
CREATE USER ' admin_user ' @ '% ' identified by ' 123456 ';
CREATE USER ' admin_user ' @ '% ' identified by ';
CREATE USER ' admin_user ' @ '% ';
Second, Authorization:
Command: GRANT privileges on databasename.tablename to ' username ' @ ' host '
Description: Privileges-user's operation permissions, such as SELECT, INSERT, UPDATE, etc. if you want to grant all permissions to use all.;
DatabaseName-database name;
TableName-the table name, if you want to grant the user permission to operate on all databases and tables, * is represented, such as *. *.
Example: GRANT SELECT, INSERT on Test.user to ' admin_user '% '; #指定数据库指定权限
GRANT all on * * to ' admin_user ' @ '% '; #所有数据库
Note: A user authorized with the above command cannot authorize another user, and if you want the user to be authorized to do so, use the following command:
GRANT privileges on Databasename.tablename to ' username ' @ ' host ' with GRANT OPTION; after authorization, enter the command: FLUSH privileges and restart the MySQL service.
Three. setting and changing user passwords
Command: SET PASSWORD for ' username ' @ ' host ' = PASSWORD (' NewPassword '); #如果是当前登陆用户用SET PASSWORD = PASSWORD ("NewPassword");
Example: SET PASSWORD for ' admin_user ' @ '% ' = PASSWORD ("123456");
Four. Revoke user rights
Command: REVOKE privilege on databasename.tablename from ' username ' @ ' host ';
Description: Privilege, DatabaseName, TableName-With the authorization section.
Example: REVOKE SELECT on * * from ' admin_user ' @ '% ';
Note: If you are authorizing the user ' admin_user ' @ '% ' (or similar): Grant SELECT on Test.user to ' Admin_user ',
The REVOKE Select On *. * from ' admin_user ' ('% '); the command does not revoke the user's select operation to the Users table in the test database.
Conversely, if the authorization is to use the grant SELECT on * * to ' admin_user ' @ '% ', then revoke select on the test.user from ' admin_user ' @ '% '; The command also cannot revoke the user's SELECT permission to the Users table in the test database.
Specific information can be used with the command show GRANTS for ' admin_user ' @ '% '; View.
Five. Delete a user
Command: DROP USER ' username ' @ ' host ';
MySQL Create user authorization