MySQL is the use of C/S mode, the client needs to log on to the server, then you can log in to the account is called the user, these user information is stored in the MySQL database (MySQL installation of the default database) in the user table,
such as the user's name, the user's password, the user can be on which host to log on to the server with the client, and some user rights related information is also stored in the user table.
One, create the user:
Command: CREATE USER ' username ' @ ' host ' identified by ' password ';
Description: Username-the user name that you will create, host-Specifies which host the user can log on to, if localhost is available to local users, you can use the wildcard% if you want the user to be able to log on from any remote host. Password-The user's 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 ' 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 ' @ '% ';
mysql database, the host column in the user table specifies the IP that is used to allow the user to log on, such as User=root host=192.168.1.1. This means that the root user can only access it through the 192.168.1.1 client.
This is why when the remote connection is turned on, most people directly change the host to%, for the sake of convenience.
Two, authorization:
command: GRANT privileges on databasename.tablename to ' username ' @ ' host '
Description: Privileges-The user's operation permissions, such as SELECT, INSERT, UPDATE, etc. (see the last side of the article for a detailed list). Use all if you want to grant permissions. DatabaseName-database name, tablename-table name, if you want to grant the user the appropriate operation permissions on all databases and tables, such as *.*.
Example: Grant SELECT, INSERT on Test.user to ' pig ' @ ' percent ';
GRANT all on * * to ' pig ' @ '% ';
Note: Users authorized with the above command cannot authorize other users, and if you want to allow the user to authorize, use the command :
GRANT privileges on Databasename.tablename to ' username ' @ ' host ' with GRANT option;
Three. setting and changing user passwords
Command: Set PASSWORD for ' username ' @ ' host ' = PASSWORD (' NewPassword '), if current user is logged in with set PASSWORD = PASSWORD ("NewPassword");
Example: SET PASSWORD for ' pig ' @ '% ' = 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 ' pig ' @ '% ';
Note: If you are giving the user ' pig ' @ '% ' authorization (or similar): Grant SELECT on Test.user to ' pig ' @ '% ', then use revoke select On * * from ' pig ' @ '% '; A select operation for the user table in the test database. Conversely, if the authorization is to use the grant SELECT on * * to ' pig ' @ '% ', then the revoke select on Test.user ' pig ' @ '% '; 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 ' pig ' @ '% '; View.
Five. Delete a user
Command: DROP USER ' username ' @ ' host ';
MySQL User's creation