MySQL authorization question summary _ PHP Tutorial

Source: Internet
Author: User
Summary of MySQL authorization issues. I cannot use the root account of localhost to connect to the DBA to create a user! Now we have obtained some information about authorized users in case of temporary authorization. The example grant is used to add users and create a root account using localhost. you cannot connect to the DBA Group to create a new user!

Obtain the information of authorized users for emergency purposes.

Authorization table example

Grant is used to add and create permissions for users, and revoke is used to delete user permissions.

Here are some examples of using grant to add users and create permissions:

Mysql> grant all privileges on *. * to test @ localhost identified by 'test' with grant option;

Add a test user (super user) with all local permissions, and the password is test. *. * In the ON clause indicates "all databases, all tables ". With grant option indicates that it has the grant permission.

Mysql> grant select, insert, update, delete, create, drop privileges on test. * to test1 @ '192. 168.1.0/255.255.255.0 'identified by 'test ';

This statement adds a test1 user with the password test, but it can only be connected from the class C subnet 192.168.1. for the test database, select, insert, update, delete, create, drop operation permission.

You do not need to manually refresh the authorization table to create permissions using the grant statement because it has been automatically refreshed.

To create permissions for users, you can also directly modify the authorization table:

Mysql> insert into user

Values ("localhost", "test", password ("test"), "Y ", "Y", "Y ");

Mysql> flush privileges;

These two statements have the same effect as the grant statement above, and a local test super user is added. We can see that it is much more convenient to use grant, and there is no need to flush privileges.

Mysql> insert into user (host, user, password) values ("192.168.1.0/255.255.255.0", "test1", PASSWORD ("test ")); mysql> insert into db values ("192.168.1.0/255.255.255.0", "test", "test1", "Y ", "Y", "Y", "N", "N") mysql> flush privileges;

These three statements have the same effect as the grant statement in the above two statements. They also add a connection that can only be connected from Class C subnet 192.168.1, and have the select, insert, update, delete, create, test1 user with the drop operation permission, and the password is test. To cancel a user's permissions, use the revoke statement. The revoke syntax is very similar to the grant statement. except to replace from with without the identified by and with grant option clauses, the following example uses revoke to delete user permissions:

Mysql> revoke all on test. * from test1 @ '192. 168.1.0/255.255.255.0 ';

This revoke revokes the permissions created by grant in the second sentence above, but the test1 user is not deleted and must be manually deleted from the user table:

Mysql> delete from user where user = 'test1 ';

Mysql> flush privileges;

In this way, the test1 user is completely deleted.

These are just simple usage of the MySQL authorization table. For more information, see the manual provided by MySQL.

Success! Now we get some information about authorized users for the authorization form to be used. example grant is used to add users and create users...

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.