MySQL User Management Rights Management

I'm using MariaDB database

View all MySQL users:

select distinct concat('User: \'',user, '\'@\'', host, '\'') as query from mysql.user;

 

Create a user

Create a local user

 CREATE USER 'USER'@'localhost' IDENTIFIED BY 'PASSWORD'; 

 

Create a network user

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

 

Authorize

Grant a user has access to the entire database of all the permissions (example)

GRANT ALL ON *.* TO 'USER'@'%'; 

 

Grant a user has access to a database of some rights (example)

GRANT SELECT ON DBNAME.* TO 'USER'@'%';

 

Update Authorization Form

flush privileges;

mysql user or new set flush privileges required to refresh the MySQL system privileges related tables after you change your password, otherwise there will be denied access,

Another method is to restart the mysql server to the new settings to take effect.

 

View a user's authorization

SHOW GRANTS FOR 'USER'@'%';

 

Revoke the authorization of a user

REVOKE privilegexxx ON databasenamexxx.tablenamexxx FROM 'usernamexxx'@'hostxxx';

 

(Example)

REVOKE SELECT ON *.* FROM 'USER'@'%'; 

 

Setup and change the user password

SET PASSWORD FOR 'usernamexxx'@'hostxxx' = PASSWORD('newpasswordxxx');

 

If the user is currently logged on with:

SET PASSWORD = PASSWORD("newpasswordxxx");

 

Guess you like

Origin www.cnblogs.com/ryanzheng/p/11349554.html