day18: User rights management

Users interact with the database server data, is divided into two stages:

(1) you have no right to connect up
(2) you have no right to perform this action

1, you have no right to come up connection

How the server determines whether the user has no right to connect up?

in accordance with:

1) Where are you from? Host
2) Who are you? the User
3) What is your password? password

user table of the three user information stored in the database in mysql

2, you have no right to perform this operation

In mysql, mysql library is a library, there are three tables in this library is a user table, user table stores permissions information for all users. One is the db table, db table stores information of all users in the database layer of permissions. One is tables_priv table, tables_priv table stores the information for all user rights in the surface layer.

 

User login, user can restrict user login table first, and secondly also holds the global rights for the user, if the user does not have any authority, then from the db table to find whether the user has permission to operate a database, and if not, table_priv from the table to find whether the user has permission to operate a table, if there is, then the user can follow the existing authority to operate the table.

 

First, the user management

1, see the user

First, switch to the MySQL database

use  mysql;

View all users

select  *  from  user ;

2. Create a user

Syntax: create user 'username' @ 'hostname' identified by 'password';

create user 'zhangsan'@'localhost' identified by '123456';

3, change the user password

Syntax: update user set password = password ( 'new password') where user = 'username';

update user set password=password('123') where user='zhangsan';

It needs to be refreshed after the completion of the following to change the password, or the password will not be changed, execute the following statement to refresh:

flush privileges;

4, delete users

Syntax: drop user 'username' @ 'hostname';

drop user 'zhangsan'@'localhost';

 

Second, rights management

1, the query permissions

Syntax: show grants for 'username' @ 'hostname';

show grants for 'root'@'localhost';
show grants for 'zhangsan'@'localhost';

2, grant permissions

Syntax: grant permissions list on the name of the database table name to 'username' @ 'hostname';.

For example: Joe Smith user to grant all privileges on any table in any database

grant all on *.* to 'zhangsan'@'localhost';

For example: John Doe user to grant access to the database demo wgy table query

create user 'lishi'@'localhost' identified by '123456';
grant select on wgy.demo1 to 'lishi'@'localhost';

3, revoke privileges

Syntax: revoke the permissions list on the database name table name from 'username' @ 'hostname';.

For example: Joe Smith revoke all privileges of users

revoke all on *.* from 'zhangsan'@'localhost';

For example: John Doe revoke user access to the database demo wgy table query permissions

revoke select on wgy.demo1 from 'lishi'@'localhost';

 

Common rights: All, the Create, drop, the SELECT, INSERT, the Delete, Update

 

 

Guess you like

Origin www.cnblogs.com/wuguiyu/p/11940664.html