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

A brief discussion on the understanding of TypeScript index signatures

Table of contents 1. What is an index signature? ...

HTML scroll bar textarea attribute setting

1. Overflow content overflow settings (set whether...

Memcached method for building cache server

Preface Many web applications store data in a rel...

How to install Jenkins using Docker

Table of contents 1. Pull the image 2. Create a l...

About converting textarea text to html, that is, carriage return and line break

Description: Change the carriage return in the tex...

Windows platform configuration 5.7 version + MySQL database service

Includes the process of initializing the root use...

In-depth understanding of the use of CSS clear:both

clear:both is used to清除浮動This is the impression I...

Detailed explanation of JavaScript animation function encapsulation

Table of contents 1. Principle of animation funct...

Docker image import, export, backup and migration operations

Export: docker save -o centos.tar centos:latest #...

The latest MySQL 5.7.23 installation and configuration graphic tutorial

The detailed installation and configuration of th...

Generate OpenSSL certificates in Linux environment

1. Environment: CentOS7, Openssl1.1.1k. 2. Concep...

CSS flex several multi-column layout

Basic three-column layout .container{ display: fl...