1. Create a user:
Command: create user 'username' @ 'host' identified by 'Password ';
Description: username-the username you will create, host-specifies the host on which the user can log on. If a local user can use localhost, if you want to allow the user to log on from any remote host, you can use the wildcard %. password-the user's login password. The password can be blank. If it is blank, the user can log on to the server without the password.
Example: create user 'dog '@ 'localhost' identified by '123 ';
Create user 'pig' @ '192. 168.1.101 _ 'idendified by '123 ';
Create user 'pig' @ '%' identified by '000000 ';
Create user 'pig' @ '%' identified '';
Create user 'pig' @ '%'; create user 'countuser' @ '%' identified by 'count1234'; 2. Authorization:
Command: grant privileges on databasename. tablename to 'username' @ 'host'
Note: privileges-user operation permissions, such as select, insert, and update. use all .; databasename-Database Name, tablename-table name. If you want to grant the user the corresponding operation permissions on all databases and tables, it can be represented by *, as shown in *. *.
Example: grant select, insert on test. User to 'pig' @ '% ';
Grant all on *. * To 'pig' @ '% ';
Note: The user authorized with the preceding command cannot authorize other users. to authorize the user, run the following command:
Grant privileges on databasename. tablename to 'username' @ 'host' with grant option; example: grant select on *. * To 'countuser' @ 'count1234 ';
3. Set and change user passwords
Command: Set password for 'username' @ 'host' = PASSWORD ('newpassword'); if the current login user uses SET Password = PASSWORD ("newpassword ");
Example: Set password for 'pig' @ '%' = PASSWORD ("123456 ");
You can also:
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='name'; mysql> FLUSH PRIVILEGES; mysql> QUIT
Iv. Revoke User Permissions
Command: revoke privilege on databasename. tablename from 'username' @ 'host ';
Note: privilege, databasename, tablename-same as the authorization section.
Example: revoke select on *. * From 'pig' @ '% ';
Note: If you authorize the user 'pig' @ '%' like this (or similar): grant select on test. user to 'pig' @ '%', use revoke select on *. * From 'pig' @ '%'; the command does not cancel the Select Operation on the user table in the test database. conversely, grant select on * is used for authorization *. * To 'pig' @ '%'; then revoke select on test. user From 'pig' @ '%'; the command cannot revoke this user's SELECT statement from the user table in the test database.
Permission.
For more information, run the show grants for 'pig' @ '%' command.
5. delete a user
Command: Drop user 'username' @ 'host ';