The implementation method of creating users and authorization in MySQL, for friends who are new to mysql, you can refer to the following
Note: My operating environment is widnows xp professional + MySQL5.0
. Create a user:
Command: CREATE USER 'username'@'host' IDENTIFIED BY 'password';
Description: username - the username you will create, host - specify On which host the user can log in, if it is a local user, localhost can be used, if you want the user to log in from any remote host, you can use the wildcard %. password - the login password of the user, the password can be empty, if it is empty then 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 operation authority, such as SELECT, INSERT, UPDATE, etc. (see the end of this article for a detailed list). If you want to grant the authority, use ALL.; databasename - database name, tablename - table name, if you want to grant The user’s corresponding operation authority on all databases and tables can be represented by *, such as *.*.
Example: GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig' @'%';
Note: The user authorized by the above command cannot authorize other users. If you want the user to be authorized, use the following command:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION
; .Set and change 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 authorize user 'pig'@'%' like this (or similar): GRANT SELECT ON test.user TO 'pig'@'%', then using REVOKE SELECT ON *.* 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'@'%'; then the REVOKE SELECT 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
used Command SHOW GRANTS FOR 'pig'@'%'; View.
Five. Delete user
Command: DROP USER 'username'@'host';
Attached table: Operation authority in MySQL