One. Create user command:
CREATE USER ' username '@'host'by'password';
Description
- Username: The user name you will create
- Host: Specifies on which host the user can log on, if localhost is available to the local user, if you want the user to be able to log in from any remote host , you can use a wildcard character
%
- Password: The user's login password, password can be empty, if it is empty, the user can not need password login server
Example:
CREATE USER 'Dog'@'localhost'Identified by '123456';CREATE USER 'Pig'@'192.168.1.101_'Idendified by '123456';CREATE USER 'Pig'@'%'Identified by '123456';CREATE USER 'Pig'@'%'Identified by "';CREATE USER 'Pig'@'%';
Two. Authorization: command:
GRANT Privileges on to ' username '@'host'
Description
- Privileges: User's operation permissions, such as,,
SELECT
INSERT
UPDATE
etc., if the permission to be granted is usedALL
- DatabaseName: Database name
- TableName: Table name, if you want to grant the user the appropriate operation permissions on all databases and tables
*
, the representation is available, such as*.*
Example:
GRANT SELECT,INSERT onTest.User to 'Pig'@'%';GRANT All on *.* to 'Pig'@'%';GRANT All onMaindataplus.* to 'Pig'@'%';
Attention:
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 to ' username '@'host'withGRANTOPTION;
Three. Set and change user password commands:
SET for ' username '@'host'= PASSWORD ('newpassword');
If the current user is logged in with:
SET = PASSWORD ("NewPassword");
Example:
SET for ' Pig '@'%'= PASSWORD ("123456");
Four. Revoke User Rights command:
REVOKE on from ' username '@'host';
Description
Privilege, DatabaseName, TableName: With the authorization section
Example:
REVOKE SELECT on *. * from ' Pig '@'%';
Attention:
If you ‘pig‘@‘%‘
are doing this (or the like) when authorizing a user, the use of a GRANT SELECT ON test.user TO ‘pig‘@‘%‘
command does REVOKE SELECT ON *.* FROM ‘pig‘@‘%‘;
not revoke the user's action on the users table in the test database SELECT
. Conversely, if authorization is used, GRANT SELECT ON *.* TO ‘pig‘@‘%‘;
the REVOKE SELECT ON test.user FROM ‘pig‘@‘%‘;
command cannot revoke the user's permissions to the users table in the test database Select
.
Specific information can be viewed with commands SHOW GRANTS FOR ‘pig‘@‘%‘;
.
Five. Delete User command:
DROP USER ' username '@'host';
MySQL Create user and authorization