Transfer mysql: grant command and flush privileges

mysql: grant command and flush privileges

2019.08.07 17:15:26 Word count 495 Reading 85

Grant is used to grant rights to users. After executing grant, do I have to execute flush privileges?

First create a user here:

create user 'ua'@'%' identified by 'pa';

In mysql, user name + address only represent one user, ua @ ip1 and ua @ ip2 are two different users.

This command will insert a row in the mysql.user table. The newly created user will have a value of N in all the permission fields before the authorization.

There are different ranges of user rights, which are explained below from large to small:

1. Global permissions

Acting on the entire Mysql instance, the weighting statement is as follows:

grant all privileges on *.* to 'ua'@'%' with grant option; 

This statement will set the value of all the permission fields of the ua user in the user table to Y.

In a production environment, users are generally not given such large permissions. If you want to revoke permissions, you can use the following command:

revoke all privileges on *.* from 'ua'@'%'; 

2.DB authority

If you want user ua to have all the permissions of library db1, you can execute the following command:

grant all privileges on db1.* to 'ua'@'%' with grant option; 

The library-based authority records are stored in the mysql.db table.

3. Table permissions and column permissions

Table permissions are stored in the table mysql.tables_priv, and column permissions are stored in the table mysql.columns_priv.

The empowerment commands are as follows:

create table db1.t1(id int, a int); grant all privileges on db1.t1 to 'ua'@'%' with grant option; GRANT SELECT(id), INSERT (id,a) ON mydb.mytbl TO 'ua'@'%' with grant option; 

The three permission categories described above will not only modify the data table when granting, but also modify the hash structure in memory. In this way, the existing connection will be affected immediately, and no flush privileges statement is required.

The flush privileges statement will clear the acl_users array in memory, reload the data from the mysql.user table and load it into the acl_users array.

Under normal circumstances, flush privileges are not required after grant.

4. Usage scenarios of flush privileges

When the permission data in the data table is inconsistent with the permission data in the memory, use flush privileges to reconstruct the memory data to reach a consistent state.
This inconsistency is usually caused by irregular operations, such as using the DML operating system permission table directly.

 
 

 

 

Guess you like

Origin www.cnblogs.com/ruiruiblog/p/12743466.html