Server 层混杂信息字典表 | 全方位认识 information_schema(下)

简介: 上期《Server 层混杂信息字典表 | 全方位认识 information_schema(中)》继续为大家介绍了部分关于Server层混杂信息字典表的知识,本期“Server层混杂信息字典表(下)”将继续为大家介绍。

上期《Server 层混杂信息字典表 | 全方位认识 information_schema(中)》继续为大家介绍了部分关于Server层混杂信息字典表的知识,本期“Server层混杂信息字典表(下)”将继续为大家介绍。


10、SCHEMA_PRIVILEGES

该表提供查询关于库级别的权限信息,每种类型的库级别权限记录一行信息

  • 该表中的信息来自mysql.db表

  • 该表为Memory引擎临时表

下面是该表中存储的信息内容

# 创建一个库级别权限的帐号
root@localhost : information_schema 06:50:42> grant all on sbtest.* to test@'%' identified by 'test';
Query OK, 0 rows affected, 1 warning (0.01 sec)

# 查询这个帐号的库级别权限
root@localhost : information_schema 06:52:31>  select * from SCHEMA_PRIVILEGES where GRANTEE="'test'@'%'";
+------------+---------------+--------------+-------------------------+--------------+
| GRANTEE    | TABLE_CATALOG | TABLE_SCHEMA | PRIVILEGE_TYPE          | IS_GRANTABLE |
+------------+---------------+--------------+-------------------------+--------------+
| 'test'@'%' | def          | sbtest      | SELECT                  | NO          |
| 'test'@'%' | def          | sbtest      | INSERT                  | NO          |
| 'test'@'%' | def          | sbtest      | UPDATE                  | NO          |
| 'test'@'%' | def          | sbtest      | DELETE                  | NO          |
| 'test'@'%' | def          | sbtest      | CREATE                  | NO          |
| 'test'@'%' | def          | sbtest      | DROP                    | NO          |
| 'test'@'%' | def          | sbtest      | REFERENCES              | NO          |
| 'test'@'%' | def          | sbtest      | INDEX                  | NO          |
| 'test'@'%' | def          | sbtest      | ALTER                  | NO          |
| 'test'@'%' | def          | sbtest      | CREATE TEMPORARY TABLES | NO          |
| 'test'@'%' | def          | sbtest      | LOCK TABLES            | NO          |
| 'test'@'%' | def          | sbtest      | EXECUTE                | NO          |
| 'test'@'%' | def          | sbtest      | CREATE VIEW            | NO          |
| 'test'@'%' | def          | sbtest      | SHOW VIEW              | NO          |
| 'test'@'%' | def          | sbtest      | CREATE ROUTINE          | NO          |
| 'test'@'%' | def          | sbtest      | ALTER ROUTINE          | NO          |
| 'test'@'%' | def          | sbtest      | EVENT                  | NO          |
| 'test'@'%' | def          | sbtest      | TRIGGER                | NO          |
+------------+---------------+--------------+-------------------------+--------------+
18 rows in set (0.00 sec)


字段含义如下(该表中所有字段为 "MySQL extension" 列)

  • GRANTEE:表示权限对应的账户名称

  • TABLE_CATALOG:该字段总是为def

  • TABLE_SCHEMA:表示权限对应的数据库名称

  • PRIVILEGE_TYPE:表示权限列别,如:SELECT、TRIGGER等

  • IS_GRANTABLE:表示拥有该权限的账户是否可给其他人授予该权限,注意:只有帐号拥有grant option权限时才为YES,否则该字段为NO

PS:该表中记录的权限也可以通过show语句查询或者查询mysql.db表

# show语句查询
root@localhost : information_schema 06:53:19> show grants for test@'%';
+--------------------------------------------------+
| Grants for test@%                                |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'%'                |
| GRANT ALL PRIVILEGES ON `sbtest`.* TO 'test'@'%' |
+--------------------------------------------------+
2 rows in set (0.00 sec)

# 查询mysql.db表
root@localhost : information_schema 06:52:37> select * from mysql.db where user='test'\G;
*************************** 1. row ***************************
            Host: %
              Db: sbtest
            User: test
      Select_priv: Y
      Insert_priv: Y
      Update_priv: Y
      Delete_priv: Y
      Create_priv: Y
        Drop_priv: Y
      Grant_priv: N
  References_priv: Y
      Index_priv: Y
      Alter_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Create_view_priv: Y
  Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
    Execute_priv: Y
      Event_priv: Y
    Trigger_priv: Y
1 row in set (0.00 sec)


11、TABLE_PRIVILEGES

该表提供查询关于表级别权限信息,该表中的内容来自mysql.tables_priv

  • 该表为Memory引擎临时表

下面是该表中存储的信息内容

# 创建测试帐号
root@localhost : information_schema 12:17:33> grant all on sbtest.sbtest1 to 'test_table'@'%' identified by 'test';
Query OK, 0 rows affected, 1 warning (0.00 sec)

# 查询该帐号的表级别权限
root@localhost : information_schema 12:18:20> select * from TABLE_PRIVILEGES where GRANTEE="'test_table'@'%'";
+------------------+---------------+--------------+------------+----------------+--------------+
| GRANTEE          | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | PRIVILEGE_TYPE | IS_GRANTABLE |
+------------------+---------------+--------------+------------+----------------+--------------+
|
 'test_table'@'%' | def          | sbtest      | sbtest1    | SELECT        | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | INSERT        | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | UPDATE        | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | DELETE        | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | CREATE        | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | DROP          | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | REFERENCES    | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | INDEX          | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | ALTER          | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | CREATE VIEW    | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | SHOW VIEW      | NO          |
| 'test_table'@'%' | def          | sbtest      | sbtest1    | TRIGGER        | NO          |
+------------------+---------------+--------------+------------+----------------+--------------+
12 rows in set (0.00 sec)


表字段含义:

  • GRANTEE:权限拥有者,即账户名称

  • TABLE_CATALOG:该字段总是为def

  • TABLE_SCHEMA:表级别权限涉及的表所属的数据库名称

  • TABLE_NAME:表级别权限涉及的表名称

  • PRIVILEGE_TYPE:权限类型,有效值为:SELECT、INSERT、UPDATE、DELETE、CREATE、DROP、REFERENCES、ALTER、INDEX、CREATE VIEW、SHOW VIEW、TRIGGER

  • IS_GRANTABLE:拥有该权限的用户是否可以将此权限授予给其他人,注意:只有帐号拥有grant option权限时才为YES,否则该字段为NO

PS:该表中的内容还可以使用show语句和mysql.tables_priv表查看

# show语句
root@localhost : information_schema 12:19:14> show grants for test_table@'%';
+----------------------------------------------------------------+
| Grants for test_table@%                                        |
+----------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test_table'@'%'                        |
| GRANT ALL PRIVILEGES ON `sbtest`.`sbtest1` TO 'test_table'@'%' |
+----------------------------------------------------------------+
2 rows in set (0.00 sec)

# mysql.tables_priv表
root@localhost : information_schema 12:21:01> select * from mysql.tables_priv where user='test_table'\G;
*************************** 1. row ***************************
  Host: %
    Db: sbtest
  User: test_table
Table_name: sbtest1
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.00 sec)


12、USER_PRIVILEGES

该表提供查询全局权限的信息,该表中的信息来自mysql.user表

  • 该表为Memory引擎临时表

下面是该表中存储的信息内容

# 创建测试帐号
root@localhost : information_schema 12:42:02> grant all on *.* to test_user@'%' identified by 'test';
Query OK, 0 rows affected, 1 warning (0.00 sec)

# 查看USER_PRIVILEGES 表
root@localhost : information_schema 12:44:59>  select * from USER_PRIVILEGES where GRANTEE="'test_user'@'%'";
+-----------------+---------------+-------------------------+--------------+
| GRANTEE        | TABLE_CATALOG | PRIVILEGE_TYPE          | IS_GRANTABLE |
+-----------------+---------------+-------------------------+--------------+
|
 'test_user'@'%' | def          | SELECT                  | NO          |
| 'test_user'@'%' | def          | INSERT                  | NO          |
| 'test_user'@'%' | def          | UPDATE                  | NO          |
| 'test_user'@'%' | def          | DELETE                  | NO          |
| 'test_user'@'%' | def          | CREATE                  | NO          |
| 'test_user'@'%' | def          | DROP                    | NO          |
| 'test_user'@'%' | def          | RELOAD                  | NO          |
| 'test_user'@'%' | def          | SHUTDOWN                | NO          |
| 'test_user'@'%' | def          | PROCESS                | NO          |
| 'test_user'@'%' | def          | FILE                    | NO          |
| 'test_user'@'%' | def          | REFERENCES              | NO          |
| 'test_user'@'%' | def          | INDEX                  | NO          |
| 'test_user'@'%' | def          | ALTER                  | NO          |
| 'test_user'@'%' | def          | SHOW DATABASES          | NO          |
| 'test_user'@'%' | def          | SUPER                  | NO          |
| 'test_user'@'%' | def          | CREATE TEMPORARY TABLES | NO          |
| 'test_user'@'%' | def          | LOCK TABLES            | NO          |
| 'test_user'@'%' | def          | EXECUTE                | NO          |
| 'test_user'@'%' | def          | REPLICATION SLAVE      | NO          |
| 'test_user'@'%' | def          | REPLICATION CLIENT      | NO          |
| 'test_user'@'%' | def          | CREATE VIEW            | NO          |
| 'test_user'@'%' | def          | SHOW VIEW              | NO          |
| 'test_user'@'%' | def          | CREATE ROUTINE          | NO          |
| 'test_user'@'%' | def          | ALTER ROUTINE          | NO          |
| 'test_user'@'%' | def          | CREATE USER            | NO          |
| 'test_user'@'%' | def          | EVENT                  | NO          |
| 'test_user'@'%' | def          | TRIGGER                | NO          |
| 'test_user'@'%' | def          | CREATE TABLESPACE      | NO          |
+-----------------+---------------+-------------------------+--------------+
28 rows in set (0.00 sec)


字段含义如下(该表中所有的字段都为 "MySQL extension" 列)

  • GRANTEE:权限拥有者,即账户名称

  • TABLE_CATALOG:该字段总是为def

  • PRIVILEGE_TYPE:权限类型

  • IS_GRANTABLE:拥有该权限的账户是否可以把该权限授予其他人,注意:只有帐号拥有grant option权限时才为YES,否则该字段为NO

该表中的信息还可以使用show语句或者mysql.user表查看

# show语句
root@localhost : information_schema 12:45:35> show grants for test_user@'%';
+------------------------------------------------+
| Grants for test_user@%                        |
+------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'test_user'@'%' |
+------------------------------------------------+
1 row in set (0.00 sec)

# 查询mysql.user表
root@localhost : information_schema 12:46:18> select * from mysql.user where user='test_user'\G;
*************************** 1. row ***************************
              Host: %
              User: test_user
      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: N
  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: *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
  password_expired: N
password_last_changed: 2018-01-29 00:44:59
password_lifetime: NULL
    account_locked: N
1 row in set (0.00 sec)


本期内容就介绍到这里,本期内容参考链接如下:

  • https://dev.mysql.com/doc/refman/5.7/en/status-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/variables-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/optimizer-trace-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/plugins-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/processlist-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/profiling-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/character-sets-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/collations-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/column-privileges-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/schema-privileges-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/table-privileges-table.html

  • https://dev.mysql.com/doc/refman/5.7/en/user-privileges-table.html



| 作者简介

罗小波·沃趣科技数据库技术专家

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
人工智能 算法 决策智能
【五子棋实战】第2章 博弈树负值极大alpha-beta剪枝算法(一)
市面上比较常用的五子棋算法是博弈树极大极小值alpha-beta剪枝算法,该算法可以分成四个部分来讲解,它们是环环相扣的:博弈树 - 极大极小值搜索 - 负值极大法 - alpha&beta剪枝 。
1813 0
|
5月前
|
人工智能 运维 API
阿里云千问大模型完整指南:功能、参数与各类订阅方案详解
阿里云千问系列大模型依托百炼MaaS平台提供标准化调用服务,覆盖文本对话、多模态交互、代码开发、自主智能体等全类业务场景,面向个人开发者、小型团队与中大型企业提供分层模型版本、灵活参数配置体系以及多样化付费订阅模式。2026年平台持续更新模型能力与优惠政策,同步适配OpenClaw、Hermes Agent、Qwen Code等主流AI智能体与编程工具,兼顾轻量化日常使用和企业级复杂长周期任务。本文从模型功能划分、核心参数配置、多类订阅方案、选型建议与故障排查五大板块完整拆解,帮助使用者根据自身场景匹配对应模型、合理控制调用成本、规范完成API接入。
2124 4
|
5月前
|
人工智能 搜索推荐 新能源
制造业B2B工厂如何通过GEO让AI主动推荐你:3步落地指南
传统搜索引擎流量被AI蚕食,采购决策者正转向生成式AI初筛供应商。本文拆解GEO(生成式引擎优化)逻辑,提供工厂老板可落地的3步实操法与3个效果监测指标,助你信息进入AI推荐名单。
623 1
|
移动开发 前端开发 JavaScript
HTML5实现好看的博客网站模板源码
HTML5实现的精美博客网站模板,适用于个人博客、简历等多种场景。代码简洁规范,页面干净整洁,内置首页、列表、文章等通用模板,支持多种风格切换,兼容性强,易于扩展和修改,附带完整注释,适合初学者上手。提供源码下载及在线预览,方便直接使用或二次开发。
1195 1
HTML5实现好看的博客网站模板源码
|
供应链 搜索推荐 Oracle
一文看懂 供应链管理系统:是什么,功能模块,怎么定制开发?
供应链管理系统就像企业的“智能管家”,帮助企业高效管理采购、生产、库存、物流和销售等环节。对于新手来说,它不仅能减少人为错误、优化库存、提升客户满意度,还能通过自动化流程节省大量时间和成本。无论是电商、小工厂还是个性化定制企业,都能找到适合自己的解决方案,尤其通过低代码平台(如Zoho Creator),无需编程也能轻松搭建专属系统。从基础功能入手,逐步优化,小企业也能实现高效运营,让生意越做越顺。
2007 0
|
算法
广度优先遍历(BFS):逐层探索图的算法奥秘
在图论中,广度优先遍历(Breadth-First Search,BFS)是一种图遍历算法,它以一种逐层的方式探索图的节点。通过从起始节点开始,逐层向外扩展,BFS能够帮助我们解决许多与图相关的问题。
799 0
|
存储 安全 Ubuntu
Linux dump命令教程
绍了Linuxdump命令的功能,包括用于备份整个文件系统的全备份和增量备份,以及如何在不同Linux发行版中安装和使用dump命令。
966 16
|
Java Maven 开发工具
记录一次Maven无法打包的排查过程
【5月更文挑战第3天】记录一次WhatTheFuck经历
1237 2
记录一次Maven无法打包的排查过程
|
安全 网络安全 网络虚拟化
零信任SDP是什么,有什么作用
综上所述,零信任SDP通过其独特的安全架构为企业网络安全提供了强大的保护屏障。在网络威胁日益增多的当代,采用零信任SDP可以帮助企业防范安全风险,保护敏感数据,同时为用户提供高效便捷的访问体验。
1363 4
|
持续交付 jenkins Devops
云效流水线 Flow测评
从入门到实践,多方位带你领略云效Flow的优与劣
1835 8