How to use DCL to manage users and control permissions in MySQL

How to use DCL to manage users and control permissions in MySQL

DCL (Data Control Language): Data control language, used to define database access rights and security levels, and to create users.

1. Manage Users

1. Create a user

-- Create a user CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';

CREATE USER 'Summerday'@'localhost' IDENTIFIED BY '123456';

ps: If [The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement] FLUSH PRIVILEGES ; statement first.

2. Modify user

-- Change password SET PASSWORD FOR 'user name'@'host name' = PASSWORD('new password');

SET PASSWORD FOR 'Summerday'@'localhost' = PASSWORD('hyh123');

3. Query users

-- 1. Switch to mysql database USE mysql;
-- 2. Query the user table SELECT * FROM USER;

The % wildcard matches everything.

4. Delete User

-- Delete user DROP USER 'username'@'hostname';

DROP USER 'Summerday'@'localhost';

2. Permission Management

1. Query permissions

-- Query permissions SHOW GRANTS FOR 'user name'@'host name';

SHOW GRANTS FOR 'Summerday'@'localhost';

2. Grant permissions

-- Grant permissions GRANT permission list ON database name. table name TO 'user name'@'host name';

GRANT SELECT ON mydb2.account TO 'Summerday'@'localhost';

-- Grant all permissions GRANT ALL ON *.* TO 'Summerday'@'localhost';

3. Revoke permissions

-- Revoke permissions REVOKE permission list ON database name. table name FROM 'user name'@'host name';

REVOKE SELECT ON mydb2.account TO 'Summerday'@'localhost';

-- Revoke all permissions REVOKE ALL ON *.* FROM 'Summerday'@'localhost';

Author: Tianqiao Baxia Source: https://www.cnblogs.com/summerday152/
This article has been included in Gitee: https://gitee.com/tqbx/JavaBlog
If you are interested, you can visit my personal website: https://www.hyhwky.com

The above is the details of how MySQL uses DCL to manage users and control permissions. For more information about MySQL management users and control permissions, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to create users and manage permissions in MySQL
  • Example analysis of mysql user rights management
  • Detailed explanation of MySQL user and permission management
  • In-depth explanation of MySQL user account management and permission management
  • Detailed explanation of MySQL user rights verification and management methods
  • Detailed explanation of MySQL user rights management
  • Summary of basic user and permission management methods in MySQL
  • Detailed explanation of MySQL user rights management

<<:  How to install mysql in docker

>>:  An article to help you learn more about JavaScript arrays

Recommend

Use nexus as a private library to proxy docker to upload and download images

1. Nexus configuration 1. Create a docker proxy U...

About WeChat Mini Program to implement cloud payment

Table of contents 1. Introduction 2. Thought Anal...

Do you know how to use mock in vue project?

Table of contents first step: The second step is ...

The use of setState in React and the use of synchronous and asynchronous

In react, if you modify the state directly using ...

Detailed explanation of mysql download and installation process

1: Download MySql Official website download addre...

11 Examples of Advanced Usage of Input Elements in Web Forms

1. Cancel the dotted box when the button is press...

Detailed explanation of GaussDB for MySQL performance optimization

Table of contents background Inspiration comes fr...

How to manually scroll logs in Linux system

Log rotation is a very common function on Linux s...

How to implement remote automatic backup of MongoDB in Linux

Preface After reading the previous article about ...

Nginx reverse proxy springboot jar package process analysis

The common way to deploy a springboot project to ...

Docker exec executes multiple commands

The docker exec command can execute commands in a...

Zabbix implements monitoring of multiple mysql processes

Three MySQL instance processes are started on one...

HTML+CSS div solution when relative width and absolute width conflict

Div solution when relative width and absolute wid...