User authorization in Mysql and ways to remove authorization _mysql

Source: Internet
Author: User

User Authorization method

You can add a new user by issuing a GRANT statement:

shell> mysql--user=root mysql
mysql> GRANT all privileges in *.* to Monty@localhost
identified by ' some  Thing ' 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:

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:

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:

Grant privileges on Databasename.tablename to ' username ' @ ' host ' with Grant OPTION;

Three. Set up and change user password

Command:

SET PASSWORD for ' username ' @ ' host ' = PASSWORD (' NewPassword ');

If the current login user is using

SET PASSWORD = PASSWORD ("NewPassword");

Example:

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:

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:

%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.) )

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.