MySQL user management: add users, authorize, delete users, revoke permissions

table of Contents

1. Log in to the database as the root user and run the following command

Second, revoke authority


1. Log in to the database as the root user and run the following command

1. Create the data_exchange database

create database data_exchange character set utf8; 

2. Create user kangll with a password of kangll 

CREATE USER 'kangll'@'%' IDENTIFIED BY 'kangll';

During the creation process, only the user name is given, but the host name is not specified, then the host name defaults to "%", which means a group of hosts, that is, permissions are open to all hosts.

Modify user password

update mysql.user set password = password('knagll') where user = 'knagll' and host = '%';
flush privileges;

3. Authorize kangll user to have all permissions of the data_exchange database (all permissions of a database)

grant all privileges on data_exchange.* to 'kangll'@'%' identified by 'kangll';

4. Set permissions on the data_exchange database (addition, deletion, modification, and check can be set to one or more) data_exchange: database, kangll: user

grant create, select, insert, update, delete on data_exchange.* to kangll@'%';
flush privileges;   //刷新系统权限表,即时生效

5. Delete user kangll

drop user kangll@'%';

6. Display the list of privileges authorized by kangll user

show grants for kangll@'%';

Second, revoke authority

1. Grant works on the entire MySQL server

grant select on *.* to kangll@localhost; -- kangll 可以查询 MySQL 中所有数据库中的表。 

grant all on *.* to kangll@localhost; -- knagll 可以管理 MySQL 中的所有数据库 

2. Revoke the user's authority to a database 

REVOKE privilege ON data_exchange.* FROM 'kangll'@'%';

 

 

Guess you like

Origin blog.csdn.net/qq_35995514/article/details/108094353