Summary of methods for querying MySQL user permissions

Summary of methods for querying MySQL user permissions

Introduce two methods to view MySQL user permissions

1. Use MySQL grants command

mysql> show grants for username@localhost;

+---------------------------------------------------------------------+

| Grants for root@localhost |

+---------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |

+---------------------------------------------------------------------+

It should be noted that:

● The combination of username and ip must exist in the mysql.user table. You can check it by using the select * from mysql.user command.

● If the IP address is in wildcard format, it needs to be enclosed in quotation marks, for example: show grants for root@'172.%';

2. Use MySQL select command

mysql> select * from mysql.user where user='root' and host='localhost' \G;
*************************** 1. row ***************************
Host: localhost
User: root
Password: **********************
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:mysql_native_password
authentication_string:
password_expired: N
1 row in set (0.01 sec)

Knowledge point expansion:

Let's create a test account test and grant table-level permissions

mysql> drop user test;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on MyDB.kkk to test@'%' identified by 'test';
Query OK, 0 rows affected (0.01 sec)
mysql> 
mysql> show grants for test;
+---------------------------------------------------------------------------------------------------------------------+
| Grants for test@% |
+---------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |
| GRANT ALL PRIVILEGES ON `MyDB`.`kkk` TO 'test'@'%' |
+---------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> select * from mysql.tables_priv\G;
*************************** 1. row ***************************
Host: %
Db: MyDB
User: test
Table_name: kkk
Grantor: root@localhost
Timestamp: 0000-00-00 00:00:00
Table_priv: Select,Insert,Update,Delete,Create,Drop,References,Index,Alter,Create View,Show view,Trigger
Column_priv: 
1 row in set (0.01 sec)
ERROR: 
No query specified
mysql> <br>

Let's create a test account test and grant column-level permissions

mysql> drop user test;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select (id, col1) on MyDB.TEST1 to test@'%' identified by 'test';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> 
mysql> select * from mysql.columns_priv;
+------+------+------+------------+-------------+---------------------+-------------+
| Host | Db | User | Table_name | Column_name | Timestamp | Column_priv |
+------+------+------+------------+-------------+---------------------+-------------+
| % | MyDB | test | TEST1 | id | 0000-00-00 00:00:00 | Select |
| % | MyDB | test | TEST1 | col1 | 0000-00-00 00:00:00 | Select |
+------+------+------+------------+-------------+---------------------+-------------+
2 rows in set (0.00 sec)
mysql> show grants for test;
+---------------------------------------------------------------------------------------------------------------------+
| Grants for test@% |
+---------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |
| GRANT SELECT (id, col1) ON `MyDB`.`TEST1` TO 'test'@'%' |
+---------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> <br>

This concludes this article on the summary of methods for querying MySQL user permissions. For more information about the two methods for querying MySQL user permissions, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL permission control detailed explanation
  • Detailed tutorial on how to create a user in mysql and grant user permissions
  • Mysql modify stored procedure related permissions issue
  • How to set remote access permissions in MySQL 8.0
  • How to use DCL to manage users and control permissions in MySQL
  • How to create users and manage permissions in MySQL
  • Example analysis of mysql user rights management
  • How to enable remote access permissions in MYSQL
  • The easiest way to create a new user and grant permissions to MySQL
  • Detailed explanation of MySQL user and permission management
  • MySQL permission control details analysis

<<:  Implementation of Docker private warehouse registry deployment

>>:  The order of event execution in the node event loop

Recommend

Several reasons for not compressing HTML

The reason is simple: In HTML documents, multiple ...

Nginx learning how to build a file hotlink protection service example

Preface Everyone knows that many sites now charge...

How to install nginx in centos7

Install the required environment 1. gcc installat...

How to implement the jQuery carousel function

This article shares the implementation code of jQ...

How does Vue download non-same-origin files based on URL

Generally speaking, we can have the following two...

Vue development tree structure components (component recursion)

This article example shares the specific code of ...

What does the legendary VUE syntax sugar do?

Table of contents 1. What is syntactic sugar? 2. ...

Example code for realizing charging effect of B station with css+svg

difficulty Two mask creation of svg graphics Firs...

A simple example of how to implement fuzzy query in Vue

Preface The so-called fuzzy query is to provide q...

JavaScript imitates Taobao magnifying glass effect

This article shares the specific code for JavaScr...

Implementation code of Nginx anti-hotlink and optimization in Linux

Hide version number The version number is not hid...

Vue3 (V) Details of integrating HTTP library axios

Table of contents 1. Install axios 2. Use of axio...

Detailed explanation of the steps to build a Vue project with Vue-cli

First you need to install Vue-cli: npm install -g...

How to set the width and height of html table cells

When making web pages, you often encounter the pr...