User Authorization method
You can add a new user by issuing a GRANT statement:
The code is as follows |
Copy Code |
shell> MySQL--user=root MySQL Mysql> GRANT all privileges in *.* to Monty@localhost Identified by ' something ' with GRANT OPTION; Mysql> GRANT all privileges in *.* to monty@ "%" Identified by ' something ' with GRANT OPTION; Mysql> GRANT reload,process on *.* to Admin@localhost; Mysql> GRANT USAGE on *.* to Dummy@localhost; |
These grant statements install 3 new users
Authorized:
Command:
The code is as follows |
Copy Code |
GRANT privileges on Databasename.tablename to ' username ' @ ' host ' |
Description: Privileges-user's operation rights, such as SELECT, INSERT, UPDATE, etc. (see the end of this article for a detailed list). Use all if you want to grant the permissions you have. DatabaseName-database name, tablename-table name, available * representations, such as *.*, if you want to give the user the appropriate action rights for all databases and tables.
Example:
The code is as follows |
Copy Code |
GRANT SELECT, INSERT on Test.user to ' pig ' @ '% '; GRANT all on *.* to ' pig ' @ '% '; |
Note: Users authorized by the above command cannot authorize other users, and if they want the user to be authorized to do so, use the command:
The code is as follows |
Copy Code |
Grant privileges on Databasename.tablename to ' username ' @ ' host ' with Grant OPTION; |
Three. Set up and change user password
Command:
The code is as follows |
Copy Code |
SET PASSWORD for ' username ' @ ' host ' = PASSWORD (' NewPassword '); |
If the current login user is using
The code is as follows |
Copy Code |
SET PASSWORD = PASSWORD ("NewPassword"); |
Example:
The code is as follows |
Copy Code |
SET PASSWORD for ' pig ' @ '% ' = PASSWORD ("123456"); |
withdraw and delete user
To cancel the permissions of one user, use the REVOKE statement. The syntax of the revoke is very similar to the grant statement, except to replace with and without the indetifed by and with GRANT option clauses:
The code is as follows |
Copy Code |
REVOKE Privileges (columns) on what from user |
The user section must match the users portion of the person you want to withdraw from the original grant statement. The privileges section does not need to match, you can authorize it with the grant statement, and then use the REVOKE statement to revoke only some of the permissions.
The REVOKE statement deletes only the permissions and does not delete the user. Even if you revoke all permissions, the user record in the users table remains, which means that the user can still connect to the server. To completely remove a user, you must explicitly delete the user record from the users table with a DELETE statement:
The code is as follows |
Copy Code |
%mysql-u root mysqlmysql>delete from user->where user= "user_name" and host= "host_name"; Mysql>flush PRIVILEGES ; |
The DELETE statement deletes the user record, and the flush statement tells the server to overload the authorization table. (When you use the GRANT and REVOKE statements, the table is overloaded automatically, and you do not modify the authorization form directly.) )