MySQL之information_schema数据库详细讲解

1. 概述

information_schema 数据库跟 performance_schema 一样,都是 MySQL 自带的信息数据库。其中 performance_schema 用于性能分析,而 information_schema 用于存储数据库元数据(关于数据的数据),例如数据库名、表名、列的数据类型、访问权限等。

information_schema 中的表实际上是视图,而不是基本表,因此,文件系统上没有与之相关的文件。

mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------------------+
| Tables_in_information_schema          |
+---------------------------------------+
| CHARACTER_SETS                        |
| COLLATIONS                            |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS                               |
| COLUMN_PRIVILEGES                     |
| ENGINES                               |
| EVENTS                                |
| FILES                                 |
| GLOBAL_STATUS                         |
| GLOBAL_VARIABLES                      |
| KEY_COLUMN_USAGE                      |
| OPTIMIZER_TRACE                       |
| PARAMETERS                            |
| PARTITIONS                            |
| PLUGINS                               |
| PROCESSLIST                           |
| PROFILING                             |
| REFERENTIAL_CONSTRAINTS               |
| ROUTINES                              |
| SCHEMATA                              |
| SCHEMA_PRIVILEGES                     |
| SESSION_STATUS                        |
| SESSION_VARIABLES                     |
| STATISTICS                            |
| TABLES                                |
| TABLESPACES                           |
| TABLE_CONSTRAINTS                     |
| TABLE_PRIVILEGES                      |
| TRIGGERS                              |
| USER_PRIVILEGES                       |
| VIEWS                                 |
| INNODB_LOCKS                          |
| INNODB_TRX                            |
| INNODB_SYS_DATAFILES                  |
| INNODB_FT_CONFIG                      |
| INNODB_SYS_VIRTUAL                    |
| INNODB_CMP                            |
| INNODB_FT_BEING_DELETED               |
| INNODB_CMP_RESET                      |
| INNODB_CMP_PER_INDEX                  |
| INNODB_CMPMEM_RESET                   |
| INNODB_FT_DELETED                     |
| INNODB_BUFFER_PAGE_LRU                |
| INNODB_LOCK_WAITS                     |
| INNODB_TEMP_TABLE_INFO                |
| INNODB_SYS_INDEXES                    |
| INNODB_SYS_TABLES                     |
| INNODB_SYS_FIELDS                     |
| INNODB_CMP_PER_INDEX_RESET            |
| INNODB_BUFFER_PAGE                    |
| INNODB_FT_DEFAULT_STOPWORD            |
| INNODB_FT_INDEX_TABLE                 |
| INNODB_FT_INDEX_CACHE                 |
| INNODB_SYS_TABLESPACES                |
| INNODB_METRICS                        |
| INNODB_SYS_FOREIGN_COLS               |
| INNODB_CMPMEM                         |
| INNODB_BUFFER_POOL_STATS              |
| INNODB_SYS_COLUMNS                    |
| INNODB_SYS_FOREIGN                    |
| INNODB_SYS_TABLESTATS                 |
+---------------------------------------+
61 rows in set (0.00 sec)

2. information_schema 库中常用的表

CHARACTER_SETS 表

提供了 mysql 可用字符集的信息。SHOW CHARACTER SET; 命令从这个表获取结果。

mysql> SHOW CHARACTER SET;
+----------+---------------------------------+---------------------+--------+
| Charset  | Description                     | Default collation   | Maxlen |
+----------+---------------------------------+---------------------+--------+
| big5     | Big5 Traditional Chinese        | big5_chinese_ci     |      2 |
| dec8     | DEC West European               | dec8_swedish_ci     |      1 |
| cp850    | DOS West European               | cp850_general_ci    |      1 |
...
| eucjpms  | UJIS for Windows Japanese       | eucjpms_japanese_ci |      3 |
| gb18030  | China National Standard GB18030 | gb18030_chinese_ci  |      4 |
+----------+---------------------------------+---------------------+--------+
41 rows in set (0.07 sec)

mysql> SELECT * FROM CHARACTER_SETS;
+--------------------+----------------------+---------------------------------+--------+
| CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION                     | MAXLEN |
+--------------------+----------------------+---------------------------------+--------+
| big5               | big5_chinese_ci      | Big5 Traditional Chinese        |      2 |
| dec8               | dec8_swedish_ci      | DEC West European               |      1 |
| cp850              | cp850_general_ci     | DOS West European               |      1 |
...
| eucjpms            | eucjpms_japanese_ci  | UJIS for Windows Japanese       |      3 |
| gb18030            | gb18030_chinese_ci   | China National Standard GB18030 |      4 |
+--------------------+----------------------+---------------------------------+--------+
41 rows in set (0.00 sec)

SCHEMATA 表

当前 mysql 实例中所有数据库的信息。SHOW DATABASES; 命令从这个表获取数据。

mysql> SELECT * FROM SCHEMATA;
+--------------+--------------------+----------------------------+------------------------+----------+
| CATALOG_NAME | SCHEMA_NAME        | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |
+--------------+--------------------+----------------------------+------------------------+----------+
| def          | information_schema | utf8                       | utf8_general_ci        | NULL     |
| def          | mysql              | latin1                     | latin1_swedish_ci      | NULL     |
| def          | performance_schema | utf8                       | utf8_general_ci        | NULL     |
| def          | sys                | utf8                       | utf8_general_ci        | NULL     |
| def          | test               | utf8                       | utf8_unicode_ci        | NULL     |
+--------------+--------------------+----------------------------+------------------------+----------+
10 rows in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
10 rows in set (0.00 sec)

TABLES 表

存储数据库中的表信息(包括视图),包括表属于哪个数据库,表的类型、存储引擎、创建时间等信息。SHOW TABLES FROM XX; 命令从这个表获取结果。

mysql> SELECT * FROM TABLES;
+---------------+--------------------+------------------------------------------------------+-------------+--------------------+---------+------------+------------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+--------------------------------------------+
| TABLE_CATALOG | TABLE_SCHEMA       | TABLE_NAME                                           | TABLE_TYPE  | ENGINE             | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH    | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME         | UPDATE_TIME         | CHECK_TIME          | TABLE_COLLATION   | CHECKSUM | CREATE_OPTIONS     | TABLE_COMMENT                              |
+---------------+--------------------+------------------------------------------------------+-------------+--------------------+---------+------------+------------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+--------------------------------------------+
| def           | information_schema | CHARACTER_SETS                                       | SYSTEM VIEW | MEMORY             |      10 | Fixed      |       NULL |            384 |           0 |           16434816 |            0 |         0 |           NULL | 2018-04-23 11:51:32 | NULL                | NULL                | utf8_general_ci   |     NULL | max_rows=43690     |                                            |
| def           | information_schema | COLLATIONS                                           | SYSTEM VIEW | MEMORY             |      10 | Fixed      |       NULL |            231 |           0 |           16704765 |            0 |         0 |           NULL | 2018-04-23 11:51:32 | NULL                | NULL                | utf8_general_ci   |     NULL | max_rows=72628     |                                            |
...
| def           | zentao             | zt_usertpl                                           | BASE TABLE  | MyISAM             |      10 | Dynamic    |          0 |              0 |           0 |    281474976710655 |         1024 |         0 |              1 | 2017-08-16 16:36:45 | 2017-08-16 16:36:45 | NULL                | utf8_general_ci   |     NULL |                    |                                            |
+---------------+--------------------+------------------------------------------------------+-------------+--------------------+---------+------------+------------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+--------------------------------------------+
525 rows in set (3.03 sec)

mysql> SHOW TABLES FROM zentao;
+-------------------+
| Tables_in_zentao  |
+-------------------+
| zt_action         |
| zt_block          |
| zt_branch         |
...
| zt_usertpl        |
+-------------------+
48 rows in set (0.00 sec)

COLUMNS 表

存储表中的列信息,包括表有多少列、每个列的类型等。SHOW COLUMNS FROM schemaname.tablename 命令从这个表获取结果。

mysql> SELECT * FROM COLUMNS LIMIT 2,5;
+---------------+--------------------+----------------+--------------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+-----------------+-------------+------------+-------+------------+----------------+-----------------------+
| TABLE_CATALOG | TABLE_SCHEMA       | TABLE_NAME     | COLUMN_NAME        | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | DATETIME_PRECISION | CHARACTER_SET_NAME | COLLATION_NAME  | COLUMN_TYPE | COLUMN_KEY | EXTRA | PRIVILEGES | COLUMN_COMMENT | GENERATION_EXPRESSION |
+---------------+--------------------+----------------+--------------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+-----------------+-------------+------------+-------+------------+----------------+-----------------------+
| def           | information_schema | CHARACTER_SETS | DESCRIPTION        |                3 |                | NO          | varchar   |                       60 |                    180 |              NULL |          NULL |               NULL | utf8               | utf8_general_ci | varchar(60) |            |       | select     |                |                       |
| def           | information_schema | CHARACTER_SETS | MAXLEN             |                4 | 0              | NO          | bigint    |                     NULL |                   NULL |                19 |             0 |               NULL | NULL               | NULL            | bigint(3)   |            |       | select     |                |                       |
| def           | information_schema | COLLATIONS     | COLLATION_NAME     |                1 |                | NO          | varchar   |                       32 |                     96 |              NULL |          NULL |               NULL | utf8               | utf8_general_ci | varchar(32) |            |       | select     |                |                       |
| def           | information_schema | COLLATIONS     | CHARACTER_SET_NAME |                2 |                | NO          | varchar   |                       32 |                     96 |              NULL |          NULL |               NULL | utf8               | utf8_general_ci | varchar(32) |            |       | select     |                |                       |
| def           | information_schema | COLLATIONS     | ID                 |                3 | 0              | NO          | bigint    |                     NULL |                   NULL |                19 |             0 |               NULL | NULL               | NULL            | bigint(11)  |            |       | select     |                |                       |
+---------------+--------------------+----------------+--------------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+-----------------+-------------+------------+-------+------------+----------------+-----------------------+
5 rows in set (0.08 sec)

STATISTICS 表

表索引的信息。SHOW INDEX FROM schemaname.tablename; 命令从这个表获取结果。

mysql> SHOW INDEX FROM szhuizhong.users;
+-------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name      | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| users |          0 | PRIMARY       |            1 | UserID      | A         |        1460 |     NULL | NULL   |      | BTREE      |         |               |
| users |          0 | Account_index |            1 | Account     | A         |        1460 |     NULL | NULL   |      | BTREE      |         |               |
| users |          1 | CorpID        |            1 | FromID      | A         |           2 |     NULL | NULL   | YES  | BTREE      |         |               |
+-------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

USER_PRIVILEGES 表

用户权限表。内容源自 mysql.user 授权表。是非标准表。

mysql> SELECT * FROM USER_PRIVILEGES;
+-------------------------+---------------+-------------------------+--------------+
| GRANTEE                 | TABLE_CATALOG | PRIVILEGE_TYPE          | IS_GRANTABLE |
+-------------------------+---------------+-------------------------+--------------+
| 'mysql.sys'@'localhost' | def           | USAGE                   | NO           |
| 'root'@'%'              | def           | SELECT                  | YES          |
| 'root'@'%'              | def           | INSERT                  | YES          |
| 'root'@'%'              | def           | UPDATE                  | YES          |
| 'root'@'%'              | def           | DELETE                  | YES          |
| 'root'@'%'              | def           | CREATE                  | YES          |
| 'root'@'%'              | def           | DROP                    | YES          |
| 'root'@'%'              | def           | RELOAD                  | YES          |
| 'root'@'%'              | def           | SHUTDOWN                | YES          |
| 'root'@'%'              | def           | PROCESS                 | YES          |
| 'root'@'%'              | def           | FILE                    | YES          |
| 'root'@'%'              | def           | REFERENCES              | YES          |
| 'root'@'%'              | def           | INDEX                   | YES          |
| 'root'@'%'              | def           | ALTER                   | YES          |
| 'root'@'%'              | def           | SHOW DATABASES          | YES          |
| 'root'@'%'              | def           | SUPER                   | YES          |
| 'root'@'%'              | def           | CREATE TEMPORARY TABLES | YES          |
| 'root'@'%'              | def           | LOCK TABLES             | YES          |
| 'root'@'%'              | def           | EXECUTE                 | YES          |
| 'root'@'%'              | def           | REPLICATION SLAVE       | YES          |
| 'root'@'%'              | def           | REPLICATION CLIENT      | YES          |
| 'root'@'%'              | def           | CREATE VIEW             | YES          |
| 'root'@'%'              | def           | SHOW VIEW               | YES          |
| 'root'@'%'              | def           | CREATE ROUTINE          | YES          |
| 'root'@'%'              | def           | ALTER ROUTINE           | YES          |
| 'root'@'%'              | def           | CREATE USER             | YES          |
| 'root'@'%'              | def           | EVENT                   | YES          |
| 'root'@'%'              | def           | TRIGGER                 | YES          |
| 'root'@'%'              | def           | CREATE TABLESPACE       | YES          |
+-------------------------+---------------+-------------------------+--------------+
29 rows in set (0.00 sec)

SCHEMA_PRIVILEGES 表

方案权限表。给出了关于方案(数据库)权限的信息。内容来自 mysql.db 授权表。是非标准表。

mysql> SELECT * FROM SCHEMA_PRIVILEGES;
+-------------------------+---------------+--------------+-------------------------+--------------+
| GRANTEE                 | TABLE_CATALOG | TABLE_SCHEMA | PRIVILEGE_TYPE          | IS_GRANTABLE |
+-------------------------+---------------+--------------+-------------------------+--------------+
| 'mysql.sys'@'localhost' | def           | sys          | TRIGGER                 | NO           |
| 'root'@'%'              | def           | mysql        | SELECT                  | YES          |
| 'root'@'%'              | def           | mysql        | INSERT                  | YES          |
| 'root'@'%'              | def           | mysql        | UPDATE                  | YES          |
| 'root'@'%'              | def           | mysql        | DELETE                  | YES          |
| 'root'@'%'              | def           | mysql        | CREATE                  | YES          |
| 'root'@'%'              | def           | mysql        | DROP                    | YES          |
| 'root'@'%'              | def           | mysql        | REFERENCES              | YES          |
| 'root'@'%'              | def           | mysql        | INDEX                   | YES          |
| 'root'@'%'              | def           | mysql        | ALTER                   | YES          |
| 'root'@'%'              | def           | mysql        | CREATE TEMPORARY TABLES | YES          |
| 'root'@'%'              | def           | mysql        | LOCK TABLES             | YES          |
| 'root'@'%'              | def           | mysql        | EXECUTE                 | YES          |
| 'root'@'%'              | def           | mysql        | CREATE VIEW             | YES          |
| 'root'@'%'              | def           | mysql        | SHOW VIEW               | YES          |
| 'root'@'%'              | def           | mysql        | CREATE ROUTINE          | YES          |
| 'root'@'%'              | def           | mysql        | ALTER ROUTINE           | YES          |
| 'root'@'%'              | def           | mysql        | EVENT                   | YES          |
| 'root'@'%'              | def           | mysql        | TRIGGER                 | YES          |
+-------------------------+---------------+--------------+-------------------------+--------------+
19 rows in set (0.00 sec)

TABLE_PRIVILEGES 表

表权限表。给出了关于表权限的信息。内容源自 mysql.tables_priv 授权表。是非标准表。

mysql> SELECT * FROM TABLE_PRIVILEGES;
+-------------------------+---------------+--------------+------------+----------------+--------------+
| GRANTEE                 | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | PRIVILEGE_TYPE | IS_GRANTABLE |
+-------------------------+---------------+--------------+------------+----------------+--------------+
| 'mysql.sys'@'localhost' | def           | sys          | sys_config | SELECT         | NO           |
+-------------------------+---------------+--------------+------------+----------------+--------------+
1 row in set (0.00 sec)

COLUMN_PRIVILEGES 表

列权限表。给出了关于列权限的信息。内容源自 mysql.columns_priv 授权表。是非标准表。

mysql> SELECT * FROM COLUMN_PRIVILEGES;
Empty set (0.00 sec)

COLLATIONS 表

提供了关于各字符集的对照信息。SHOW COLLATION; 命令从这个表获取结果。

mysql> SELECT * FROM COLLATIONS;
+--------------------------+--------------------+-----+------------+-------------+---------+
| COLLATION_NAME           | CHARACTER_SET_NAME | ID  | IS_DEFAULT | IS_COMPILED | SORTLEN |
+--------------------------+--------------------+-----+------------+-------------+---------+
| big5_chinese_ci          | big5               |   1 | Yes        | Yes         |       1 |
| big5_bin                 | big5               |  84 |            | Yes         |       1 |
| dec8_swedish_ci          | dec8               |   3 | Yes        | Yes         |       1 |
| dec8_bin                 | dec8               |  69 |            | Yes         |       1 |
...
| gb18030_bin              | gb18030            | 249 |            | Yes         |       1 |
| gb18030_unicode_520_ci   | gb18030            | 250 |            | Yes         |       8 |
+--------------------------+--------------------+-----+------------+-------------+---------+
222 rows in set (0.03 sec)

COLLATION_CHARACTER_SET_APPLICABILITY 表

指明了可用于校对的字符集。相当于 SHOW COLLATION 命令结果的前两个字段。

mysql> SELECT * FROM COLLATION_CHARACTER_SET_APPLICABILITY;
+--------------------------+--------------------+
| COLLATION_NAME           | CHARACTER_SET_NAME |
+--------------------------+--------------------+
| big5_chinese_ci          | big5               |
| big5_bin                 | big5               |
| dec8_swedish_ci          | dec8               |
...
| gb18030_bin              | gb18030            |
| gb18030_unicode_520_ci   | gb18030            |
+--------------------------+--------------------+
222 rows in set (0.00 sec)

TABLE_CONSTRAINTS 表

描述了存在约束的表。以及表的约束类型。

mysql> SELECT * FROM TABLE_CONSTRAINTS;
+--------------------+-------------------+--------------------+--------------+---------------------------+-----------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME    | TABLE_SCHEMA | TABLE_NAME                | CONSTRAINT_TYPE |
+--------------------+-------------------+--------------------+--------------+---------------------------+-----------------+
| def                | mysql             | PRIMARY            | mysql        | columns_priv              | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | db                        | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | engine_cost               | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | event                     | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | func                      | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | gtid_executed             | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | help_category             | PRIMARY KEY     |
| def                | mysql             | name               | mysql        | help_category             | UNIQUE          |
| def                | mysql             | PRIMARY            | mysql        | help_keyword              | PRIMARY KEY     |
| def                | mysql             | name               | mysql        | help_keyword              | UNIQUE          |
| def                | mysql             | PRIMARY            | mysql        | help_relation             | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | help_topic                | PRIMARY KEY     |
| def                | mysql             | name               | mysql        | help_topic                | UNIQUE          |
| def                | mysql             | PRIMARY            | mysql        | innodb_index_stats        | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | innodb_table_stats        | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | ndb_binlog_index          | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | plugin                    | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | proc                      | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | procs_priv                | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | proxies_priv              | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | server_cost               | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | servers                   | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | slave_master_info         | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | slave_relay_log_info      | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | slave_worker_info         | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | tables_priv               | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | time_zone                 | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | time_zone_leap_second     | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | time_zone_name            | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | time_zone_transition      | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | time_zone_transition_type | PRIMARY KEY     |
| def                | mysql             | PRIMARY            | mysql        | user                      | PRIMARY KEY     |
| def                | sys               | PRIMARY            | sys          | sys_config                | PRIMARY KEY     |
| def                | zentao            | PRIMARY            | zentao       | zt_action                 | PRIMARY KEY     |
...
| def                | zentao            | account            | zentao       | zt_usergroup              | UNIQUE          |
| def                | zentao            | PRIMARY            | zentao       | zt_userquery              | PRIMARY KEY     |
| def                | zentao            | PRIMARY            | zentao       | zt_usertpl                | PRIMARY KEY     |
+--------------------+-------------------+--------------------+--------------+---------------------------+-----------------+
213 rows in set (0.37 sec)

KEY_COLUMN_USAGE 表

描述了具有约束的键列。

mysql> SELECT * FROM KEY_COLUMN_USAGE;
+--------------------+-------------------+--------------------+---------------+--------------+---------------------------+--------------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME    | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME                | COLUMN_NAME        | ORDINAL_POSITION | POSITION_IN_UNIQUE_CONSTRAINT | REFERENCED_TABLE_SCHEMA | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+--------------------+-------------------+--------------------+---------------+--------------+---------------------------+--------------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
| def                | mysql             | PRIMARY            | def           | mysql        | columns_priv              | Host               |                1 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | columns_priv              | Db                 |                2 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | columns_priv              | User               |                3 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | columns_priv              | Table_name         |                4 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | columns_priv              | Column_name        |                5 |                          NULL | NULL                    | NULL                  | NULL                   |
...
| def                | mysql             | PRIMARY            | def           | mysql        | time_zone_leap_second     | Transition_time    |                1 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | time_zone_name            | Name               |                1 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | time_zone_transition      | Time_zone_id       |                1 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | time_zone_transition      | Transition_time    |                2 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | time_zone_transition_type | Time_zone_id       |                1 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | time_zone_transition_type | Transition_type_id |                2 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | user                      | Host               |                1 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | mysql             | PRIMARY            | def           | mysql        | user                      | User               |                2 |                          NULL | NULL                    | NULL                  | NULL                   |
| def                | sys               | PRIMARY            | def           | sys          | sys_config                | variable           |                1 |                          NULL | NULL                    | NULL                  | NULL                   |
+--------------------+-------------------+--------------------+---------------+--------------+---------------------------+--------------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
278 rows in set (0.03 sec)

ROUTINES 表

提供了关于存储子程序(存储程序和函数)的信息。此时,ROUTINES 表不包含自定义函数(UDF)。名为“mysql.proc name”的列指明了对应于 INFORMATION_SCHEMA.ROUTINES 表的 mysql.proc 列。

VIEWS 表

给出了关于数据库中的视图的信息。需要有 show views 权限,否则无法查看视图信息。

mysql> SELECT * FROM VIEWS LIMIT 1\G
*************************** 1. row ***************************
       TABLE_CATALOG: def
        TABLE_SCHEMA: sys
          TABLE_NAME: host_summary
     VIEW_DEFINITION: select if(isnull(`performance_schema`.`accounts`.`HOST`),'background',`performance_schema`.`accounts`.`HOST`) AS `host`,sum(`stmt`.`total`) AS `statements`,`sys`.`format_time`(sum(`stmt`.`total_latency`)) AS `statement_latency`,`sys`.`format_time`(ifnull((sum(`stmt`.`total_latency`) / nullif(sum(`stmt`.`total`),0)),0)) AS `statement_avg_latency`,sum(`stmt`.`full_scans`) AS `table_scans`,sum(`io`.`ios`) AS `file_ios`,`sys`.`format_time`(sum(`io`.`io_latency`)) AS `file_io_latency`,sum(`performance_schema`.`accounts`.`CURRENT_CONNECTIONS`) AS `current_connections`,sum(`performance_schema`.`accounts`.`TOTAL_CONNECTIONS`) AS `total_connections`,count(distinct `performance_schema`.`accounts`.`USER`) AS `unique_users`,`sys`.`format_bytes`(sum(`mem`.`current_allocated`)) AS `current_memory`,`sys`.`format_bytes`(sum(`mem`.`total_allocated`)) AS `total_memory_allocated` from (((`performance_schema`.`accounts` join `sys`.`x$host_summary_by_statement_latency` `stmt` on((`performance_schema`.`accounts`.`HOST` = `stmt`.`host`))) join `sys`.`x$host_summary_by_file_io` `io` on((`performance_schema`.`accounts`.`HOST` = `io`.`host`))) join `sys`.`x$memory_by_host_by_current_bytes` `mem` on((`performance_schema`.`accounts`.`HOST` = `mem`.`host`))) group by if(isnull(`performance_schema`.`accounts`.`HOST`),'background',`performance_schema`.`accounts`.`HOST`)
        CHECK_OPTION: NONE
        IS_UPDATABLE: NO
             DEFINER: mysql.sys@localhost
       SECURITY_TYPE: INVOKER
CHARACTER_SET_CLIENT: utf8
COLLATION_CONNECTION: utf8_general_ci
1 row in set (0.03 sec)

TRIGGERS 表

提供了关于触发程序的信息。必须有 super 权限才能查看该表。

mysql> SELECT * FROM TRIGGERS LIMIT 1\G
*************************** 1. row ***************************
           TRIGGER_CATALOG: def
            TRIGGER_SCHEMA: sys
              TRIGGER_NAME: sys_config_insert_set_user
        EVENT_MANIPULATION: INSERT
      EVENT_OBJECT_CATALOG: def
       EVENT_OBJECT_SCHEMA: sys
        EVENT_OBJECT_TABLE: sys_config
              ACTION_ORDER: 1
          ACTION_CONDITION: NULL
          ACTION_STATEMENT: BEGIN IF @sys.ignore_sys_config_triggers != true AND NEW.set_by IS NULL THEN SET NEW.set_by = USER(); END IF; END
        ACTION_ORIENTATION: ROW
             ACTION_TIMING: BEFORE
ACTION_REFERENCE_OLD_TABLE: NULL
ACTION_REFERENCE_NEW_TABLE: NULL
  ACTION_REFERENCE_OLD_ROW: OLD
  ACTION_REFERENCE_NEW_ROW: NEW
                   CREATED: 2017-05-27 11:18:43.60
                  SQL_MODE:
                   DEFINER: mysql.sys@localhost
      CHARACTER_SET_CLIENT: utf8
      COLLATION_CONNECTION: utf8_general_ci
        DATABASE_COLLATION: utf8_general_ci
1 row in set (0.00 sec)

到此这篇关于MySQL之information_schema数据库详细讲解的文章就介绍到这了,更多相关MySQL之information_schema数据库内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • mysql数据库中的information_schema和mysql可以删除吗?

    新装的mysql里面有两个数据库:information_schema 和 mysql  .他们是干么用的?可以删除么?当然是不可以删除的. 1.information schema 是mysql系统用的所有字典信息,包括数据库系统有什么库,有什么表,有什么字典,有什么存储过程等所有对象信息和进程访问.状态信息.一旦删除该数据库系统将无法使用. 2.mysql数据库是保存系统有关的权限,对象和状态信息.同样是不能删除的.并且这两个数据库都很小,不占用空间,你为什么要删除呢.? mysql数据库中

  • 关于MySQL绕过授予information_schema中对象时报ERROR 1044(4200)错误

    这个问题是微信群中网友关于MySQL权限的讨论,有这么一个业务需求(下面是他的原话): 因为MySQL的很多功能都依赖主键,我想用zabbix用户,来监控业务数据库的所有表,是否都建立了主键. 监控的语句是: FROM information_schema.tables t1 LEFT OUTER JOIN information_schema.table_constraints t2 ON t1.table_schema = t2.table_schema AND t1.table_name

  • 解析MySQL的information_schema数据库

    information_schema数据库是在mysql的版本5.0之后产生的,一个虚拟数据库,物理上并不存在.information_schema数据库类似与"数据字典",提供了访问数据库元数据的方式,即数据的数据.比如数据库名或表名,列类型,访问权限(更加细化的访问方式). 其中重要的表有:SCHEMATA表---SCHEMATA表提供了当前mysql实例中所有数据库的信息.是show databases的结果取之此表.TABLES表---TABLES表提供了关于数据库中的表的信息

  • MySQL之information_schema数据库详细讲解

    1. 概述 information_schema 数据库跟 performance_schema 一样,都是 MySQL 自带的信息数据库.其中 performance_schema 用于性能分析,而 information_schema 用于存储数据库元数据(关于数据的数据),例如数据库名.表名.列的数据类型.访问权限等. information_schema 中的表实际上是视图,而不是基本表,因此,文件系统上没有与之相关的文件. mysql> use information_schema;

  • MySQL/Postgrsql 详细讲解如何用ODBC接口访问MySQL指南

    详细讲解如何用ODBC接口访问MySQL指南 MySQL的ODBC接口实现是通过安装MyODBC驱动,这个驱动程序是跨平台的.如果在Linux等Unix体系操作系统下使用,需要先安装Iodbc这些第三方ODBC标准支援平台. 简单的ASP示例代码:   复制代码 代码如下: <%   dim sql,mysql   set sql = server.createobject("adodb.connection")   mysql="driver={mysql odbc 

  • Linux上通过binlog文件恢复mysql数据库详细步骤

     一.binlog 介绍 服务器的二进制日志记录着该数据库的所有增删改的操作日志(前提是要在自己的服务器上开启binlog),还包括了这些操作的执行时间.为了显示这些二进制内容,我们可以使用mysqlbinlog命令来查看. 用途1:主从同步 用途2:恢复数据库(也是线上出现一次数据库文件丢失后,才对这个有所了解并学习的) mysqlbinlog命令用法:shell> mysqlbinlog [options] log_file ... <!--[if !supportLists]-->

  • python 3.6 +pyMysql 操作mysql数据库(实例讲解)

    版本信息:python:3.6 mysql:5.7 pyMysql:0.7.11 ################################################################# #author: 陈月白 #_blogs: http://www.cnblogs.com/chenyuebai/ ################################################################# # -*- coding: utf-8

  • MySQL之权限以及设计数据库案例讲解

    权限及设计数据库 用户管理 使用SQLyog 创建用户,并授予权限演示 基本命令 /* 用户和权限管理 */ ------------------ 用户信息表:mysql.user -- 刷新权限 FLUSH PRIVILEGES -- 增加用户 CREATE USER kuangshen IDENTIFIED BY '123456' CREATE USER 用户名 IDENTIFIED BY [PASSWORD] 密码(字符串) - 必须拥有mysql数据库的全局CREATE USER权限,或

  • Mysql超详细讲解死锁问题的理解

    目录 1.什么是死锁? 2.Mysql出现死锁的必要条件 资源独占条件 请求和保持条件 不剥夺条件 相互获取锁条件 3. Mysql经典死锁案例 3.1 建表语句 3.2 初始化相关数据 3.3 正常转账过程 3.4 死锁转账过程 3.5 死锁导致的问题 4.如何解决死锁问题? 4.1 打破请求和保持条件 4.2 打破相互获取锁条件(推荐) 5.总结 1.什么是死锁? 死锁指的是在两个或两个以上不同的进程或线程中,由于存在共同资源的竞争或进程(或线程)间的通讯而导致各个线程间相互挂起等待,如果没

  • MySQL详细讲解多表关联查询

    目录 数据库设计范式 外键 内连接 外连接 结语 数据库设计范式 目前数据库设计有五种范式 , 一般我们数据库只需要满足前三项即可 第一范式 : 确保每列保持原子性 什么是原子性? 意思就是不可再分的,例如下 联系方式有 QQ,微信 , 电话等等 , 显然此列不满足原子性, 如果是单独的QQ或者电话等,则只有一个, 满足第一范式 第二范式 : 要有主键,要求其他字段都依赖于主键 为什么主键这么重要? 我们可以这样理解, 如果把表当作一个队伍, 那么主键就是这个队伍的队旗 • 没有主键就没有唯一性

  • Java mysql详细讲解双数据源配置使用

    目录 使用方式 application.properties中数据库配置 config文件配置 1.配置 spring.datasource.db1 2.配置 spring.datasource.db2 3.截图 使用方式 application.properties中数据库配置 #数据库配置spring.datasource.db1.jdbc-url=jdbc:mysql://localhost:3306/gds?useUnicode=true&characterEncoding=utf8&am

  • Mysql表的约束超详细讲解

    目录 约束的概念 空属性 默认值 列描述 zerofill 主键 自增长 唯一键 外键 约束的概念 约束:通过限制用户操作的方式,来达到维护数据本身安全,完整性的一套方案. 为什么要有约束? Mysql是一套整体的数据存储解决方案,除了解决数据存储功能,还要保证数据的安全,减少用户的误操作. 表的约束有很多,主要介绍:null/not null,default, comment, zerofill,primary key, auto_increment,unique key . 空属性 数据库默

随机推荐