1. Create a user:
Command: CREATE USER 'username'@'host' IDENTIFIED BY 'password';
Description: username - the username you will create, host - specify which host the user can log in on, if it is a local user localhost, if you want the user to log in from any remote host, you can use the wildcard %. password - the user's login password, the password can be empty, if it is empty, the user can log in to the server without a password.
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'@'%';
Second, authorization:
Command: GRANT privileges ON databasename.tablename TO 'username'@'host'
Description: privileges - user's operating authority, such as SELECT , INSERT , UPDATE , etc. (see the end of this article for a detailed list). If you want to grant all permissions, use ALL.;databasename - database name, tablename - table name, if you want to grant the user the corresponding operation permissions on all databases and tables, you can use *, such as *.*.
Example: GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
Note: Users authorized by the above commands cannot authorize other users. To allow the user to authorize, use the following command:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
3. Set and change the user password
command: SET PASSWORD FOR 'username'@'host' = PASSWORD( 'newpassword'); If it is the current login user, use SET PASSWORD = PASSWORD("newpassword");
Example: SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");
4. Revoke user privilege
command: REVOKE privilege ON databasename.tablename FROM 'username'@'host';
Description: privilege, databasename, tablename - same as authorization part.
Example: REVOKE SELECT ON *.* FROM 'pig'@'%';
Note: If you grant user 'pig'@'%' like this (or similar): GRANT SELECT ON test.user TO 'pig'@'%', then use REVOKE SELECT ON *.* The FROM 'pig'@'%'; command cannot revoke the user's SELECT operation on the user table in the test database. On the contrary, if the authorization is GRANT SELECT ON *.* TO 'pig'@'%'; REVOKE SELECT The ON test.user FROM 'pig'@'%'; command cannot revoke the user's Select permission to the user table in the test database.
The specific information can be viewed with the command SHOW GRANTS FOR 'pig'@'%';
5. Delete User
command: DROP USER 'username'@'host';
Schedule: Operation permissions in MySQL
MySQL create user and authorization method
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326035192&siteId=291194637
Recommended
Ranking