Version:8.0.32
INFORMATION_SCHEMA
压缩
INNODB_CMP和INNODB_CMP_RESET提供有关压缩操作的数量和执行压缩所花费的时间的信息。
INNODB_CMPMEM和INNODB_CMPMEM_RESET提供有关内存分配用于压缩的方式的信息。
事务和锁
INNODB_TRX:这个INFORMATION_SCHEMA表提供了当前在InnoDB内部执行的每个事务的信息,包括事务状态(例如,是正在运行还是正在等待锁),事务何时启动,以及事务正在执行的特定SQL语句。
data_locks:这个Performance Schema表包含了每一个持有锁和每一个等待持有锁被释放的锁请求的一行。
data_lock_waits:这个Performance Schema表指示哪些事务正在等待给定的锁,或者给定的事务正在等待哪个锁。该表包含每个阻塞事务的一行或多行,指示该事务请求的锁和阻塞该请求的任何锁。REQUESTING_ENGINE_LOCK_ID值指的是事务请求的锁,BLOCKING_ENGINE_LOCK_ID值指的是阻止第一个事务继续进行的锁(由另一个事务持有)。对于任何给定的阻塞事务,data_lock_waits中的所有行对于REQUESTING_ENGINE_LOCK_ID具有相同的值,而对于
BLOCKING_ENGINE_LOCK_ID有不同值。
使用以下查询查看哪些事务正在等待,哪些事务正在阻塞它们:
SELECT
r.trx_id waiting_trx_id,
r.trx_mysql_thread_id waiting_thread,
r.trx_query waiting_query,
b.trx_id blocking_trx_id,
b.trx_mysql_thread_id blocking_thread,
b.trx_query blocking_query
FROM performance_schema.data_lock_waits w
INNER JOIN information_schema.innodb_trx b
ON b.trx_id = w.blocking_engine_transaction_id
INNER JOIN information_schema.innodb_trx r
ON r.trx_id = w.requesting_engine_transaction_id;
更简单地说,使用sys schema innodb_lock_waits视图:
SELECT
waiting_trx_id,
waiting_pid,
waiting_query,
blocking_trx_id,
blocking_pid,
blocking_query
FROM sys.innodb_lock_waits;
当标识阻塞事务时,如果发出该查询的会话已经空闲,则报告阻塞查询的NULL值。在这种情况下,使用以下步骤来确定阻塞查询:
SELECT THREAD_ID FROM performance_schema.threads WHERE PROCESSLIST_ID = 6;
SELECT THREAD_ID, SQL_TEXT FROM performance_schema.events_statements_current
WHERE THREAD_ID = 28\G
如果线程执行的最后一个查询没有足够的信息来确定为什么持有锁,您可以查询Performance Schema events_statements_history表来查看线程执行的最后10条语句
SELECT THREAD_ID, SQL_TEXT FROM performance_schema.events_statements_history
WHERE THREAD_ID = 28 ORDER BY EVENT_ID;
一个事务可以对不同的行或表有任意数量的锁请求。在任何给定的时间,一个事务可能请求另一个事务持有的锁,在这种情况下,它被另一个事务阻塞。请求事务必须等待持有阻塞锁的事务提交或回滚。如果事务没有等待锁,则处于RUNNING状态。如果事务正在等待锁,则处于lock WAIT状态。(INFORMATION_SCHEMA INNODB_TRX表表示事务状态值。)
Performance Schema data_locks表为每个LOCK WAIT事务保存一个或多个行,指示阻止其进程的任何锁请求。这个表还包含一行,描述了为给定行或表挂起的锁队列中的每个锁。Performance Schema data_lock_waits表显示了某个事务已经持有的哪些锁正在阻塞其他事务请求的锁
模式对象表
InnoDB INFORMATION_SCHEMA模式对象表包括下面列出的表
INNODB_DATAFILES
INNODB_TABLESTATS :InnoDB表的底层状态信息来源于内存数据结构。
INNODB_FOREIGN:关于InnoDB表上定义的外键的元数据
INNODB_COLUMNS :InnoDB表列的元数据
INNODB_INDEXES :InnoDB索引的元数据
INNODB_FIELDS :InnoDB索引的键列(字段)的元数据。
INNODB_TABLESPACES :InnoDB文件表和一般表空间的数据文件路径信息。
INNODB_TABLESPACES_BRIEF:InnoDB表空间元数据的子集(数据文件路径信息)。
INNODB_FOREIGN_COLS :关于定义InnoDB表在其上的外键列的元数据
INNODB_TABLES:InnoDB表的元数据
示例1:
mysql> CREATE DATABASE test;
mysql> USE test;
mysql> CREATE TABLE t1 (
col1 INT,
col2 CHAR(10),
col3 VARCHAR(10))
ENGINE = InnoDB;
mysql> CREATE INDEX i1 ON t1(col1);
查询INNODB_TABLES找到test/t1的元数据:
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME='test/t1' \G
*************************** 1. row ***************************
TABLE_ID: 71
NAME: test/t1
FLAG: 1
N_COLS: 6
SPACE: 57
ROW_FORMAT: Compact
ZIP_PAGE_SIZE: 0
INSTANT_COLS: 0
查询INNODB_COLUMNS表的列信息。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_COLUMNS where TABLE_ID = 71\G
*************************** 1. row ***************************
TABLE_ID: 71
NAME: col1
POS: 0
MTYPE: 6
PRTYPE: 1027
LEN: 4
HAS_DEFAULT: 0
DEFAULT_VALUE: NULL
*************************** 2. row ***************************
TABLE_ID: 71
NAME: col2
POS: 1
MTYPE: 2
PRTYPE: 524542
LEN: 10
HAS_DEFAULT: 0
DEFAULT_VALUE: NULL
*************************** 3. row ***************************
TABLE_ID: 71
NAME: col3
POS: 2
MTYPE: 1
PRTYPE: 524303
LEN: 10
HAS_DEFAULT: 0
DEFAULT_VALUE: NULL
查询INNODB_INDEXES查询表t1相关的索引信息。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_INDEXES WHERE TABLE_ID = 71 \G
*************************** 1. row ***************************
INDEX_ID: 111
NAME: GEN_CLUST_INDEX
TABLE_ID: 71
TYPE: 1
N_FIELDS: 0
PAGE_NO: 3
SPACE: 57
MERGE_THRESHOLD: 50
*************************** 2. row ***************************
INDEX_ID: 112
NAME: i1
TABLE_ID: 71
TYPE: 0
N_FIELDS: 1
PAGE_NO: 4
SPACE: 57
MERGE_THRESHOLD: 50
查询INNODB_FIELDS查询索引i1的字段信息。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FIELDS where INDEX_ID = 112 \G
*************************** 1. row ***************************
INDEX_ID: 112
NAME: col1
POS: 0
使用INNODB_TABLES表中的SPACE信息,查询INNODB_TABLESPACES表的表空间信息。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE SPACE = 57 \G
*************************** 1. row ***************************
SPACE: 57
NAME: test/t1
FLAG: 16417
ROW_FORMAT: Dynamic
PAGE_SIZE: 16384
ZIP_PAGE_SIZE: 0
SPACE_TYPE: Single
FS_BLOCK_SIZE: 4096
FILE_SIZE: 114688
ALLOCATED_SIZE: 98304
SERVER_VERSION: 8.0.4
SPACE_VERSION: 1
ENCRYPTION: N
再次使用INNODB_TABLES表中的SPACE信息,查询INNODB_DATAFILES表空间数据文件的位置。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_DATAFILES WHERE SPACE = 57 \G
*************************** 1. row ***************************
SPACE: 57
PATH: ./test/t1.ibd
mysql> INSERT INTO t1 VALUES(5, 'abc', 'def');
Query OK, 1 row affected (0.06 sec)
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESTATS where TABLE_ID = 71 \G
*************************** 1. row ***************************
TABLE_ID: 71
NAME: test/t1
STATS_INITIALIZED: Initialized
NUM_ROWS: 1
CLUST_INDEX_SIZE: 1
OTHER_INDEX_SIZE: 0
MODIFIED_COUNTER: 1
AUTOINC: 0
REF_COUNT: 1
示例2:
mysql> CREATE DATABASE test;
mysql> USE test;
mysql> CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)) ENGINE=INNODB;
mysql> CREATE TABLE child (id INT, parent_id INT,
INDEX par_ind (parent_id),
CONSTRAINT fk1
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE) ENGINE=INNODB;
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FOREIGN \G
*************************** 1. row ***************************
ID: test/fk1
FOR_NAME: test/child
REF_NAME: test/parent
N_COLS: 1
TYPE: 1
使用外键ID查询INNODB_FOREIGN_COLS,查看外键列的数据。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FOREIGN_COLS WHERE ID = 'test/fk1' \G
*************************** 1. row ***************************
ID: test/fk1
FOR_COL_NAME: parent_id
REF_COL_NAME: id
POS: 0
SELECT a.NAME, a.ROW_FORMAT,
@page_size :=IF(a.ROW_FORMAT='Compressed',b.ZIP_PAGE_SIZE, b.PAGE_SIZE) AS page_size,
ROUND((@page_size * c.CLUST_INDEX_SIZE)/(1024*1024)) AS pk_mb,
ROUND((@page_size * c.OTHER_INDEX_SIZE)/(1024*1024)) AS secidx_mb
FROM INFORMATION_SCHEMA.INNODB_TABLES a
INNER JOIN INFORMATION_SCHEMA.INNODB_TABLESPACES b on a.NAME = b.NAME
INNER JOIN INFORMATION_SCHEMA.INNODB_TABLESTATS c on b.NAME = c.NAME
WHERE a.NAME LIKE 'test/%'
ORDER BY a.NAME DESC;
全文索引表
INNODB_FT_CONFIG:INNODB_FT_CONFIG:提供关于全文索引和InnoDB表相关处理的元数据。
NNODB_FT_BEING_DELETED:提供一个INNODB_FT_DELETED表的快照;它只在优化表维护操作期间使用。当OPTIMIZE TABLE运行时,
INNODB_FT_BEING_DELETED表被清空,并且从INNODB_FT_DELETED表中删除DOC_ID值。因为INNODB_FT_BEING_DELETED的内容通常由于生命周期短,该表用于监视或调试的实用价值有限。
INNODB_FT_DELETED:存储从InnoDB表的全文索引中删除的行。为了避免在DML操作中对InnoDB全文索引进行昂贵的索引重组,新删除的单词的信息被单独存储,当你进行文本搜索时从搜索结果中过滤出来,并且只有当你对InnoDB表发出OPTIMIZE TABLE语句时才从主搜索索引中删除。
INNODB_FT_DEFAULT_STOPWORD:保存在InnoDB表上创建全文索引时默认使用的停用词列表。
INNODB_FT_INDEX_TABLE:提供了关于倒排索引的信息,用于处理针对InnoDB表的全文索引的文本搜索。
INNODB_FT_INDEX_CACHE:在全文索引中提供新插入行的标记信息。为了避免DML操作过程中昂贵的索引重组,新索引词的信息是单独存储的,只有在优化表运行时,服务器关闭时,或缓存大小超过innodb_ft_cache_size或innodb_ft_total_cache_size系统变量定义的限制时,才会与主搜索索引结合。
示例3:
这个示例使用一个带有FULLTEXT索引的表来演示FULLTEXT索引INFORMATION_SCHEMA表中包含的数据。
mysql> CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
mysql> INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
将innodb_ft_aux_table变量设置为具有FULLTEXT索引的表名。如果不设置此变量,InnoDB FULLTEXT INFORMATION_SCHEMA表为空,INNODB_FT_DEFAULT_STOPWORD除外。
SET GLOBAL innodb_ft_aux_table = 'test/articles';
查询INNODB_FT_INDEX_CACHE表,该表显示了FULLTEXT索引中新插入的行信息。为了避免在DML操作期间进行昂贵的索引重组,新插入行的数据将保留在FULLTEXT索引缓存中,直到运行OPTIMIZE TABLE(或者直到服务器关闭或超过缓存限制)。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE LIMIT 5;
+------------+--------------+-------------+-----------+--------+----------+
| WORD | FIRST_DOC_ID | LAST_DOC_ID | DOC_COUNT | DOC_ID | POSITION |
+------------+--------------+-------------+-----------+--------+----------+
| 1001 | 5 | 5 | 1 | 5 | 0 |
| after | 3 | 3 | 1 | 3 | 22 |
| comparison | 6 | 6 | 1 | 6 | 44 |
| configured | 7 | 7 | 1 | 7 | 20 |
| database | 2 | 6 | 2 | 2 | 31 |
+------------+--------------+-------------+-----------+--------+----------+
启用innodb_optimize_fulltext_only系统变量,并在包含FULLTEXT索引的表上运行OPTIMIZE TABLE。此操作将FULLTEXT索引缓存的内容刷新到主FULLTEXT索引。Innodb_optimize_fulltext_only改变
OPTIMIZE TABLE语句对InnoDB表进行操作,并且在对具有FULLTEXT索引的InnoDB表进行维护操作期间临时启用。
SET GLOBAL innodb_optimize_fulltext_only=ON;
OPTIMIZE TABLE articles;
启用innodb_optimize_fulltext_only系统变量,并在包含FULLTEXT索引的表上运行OPTIMIZE TABLE。此操作将FULLTEXT索引缓存的内容刷新到主FULLTEXT索引。Innodb_optimize_fulltext_only改变
OPTIMIZE TABLE语句对InnoDB表进行操作,并且在对具有FULLTEXT索引的InnoDB表进行维护操作期间临时启用。
SET GLOBAL innodb_optimize_fulltext_only=ON;
OPTIMIZE TABLE articles;
查询INNODB_FT_INDEX_TABLE表可以查看主FULLTEXT索引中的数据信息,包括刚刚从FULLTEXT索引缓存中刷新的数据信息
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE LIMIT 5;
+------------+--------------+-------------+-----------+--------+----------+
| WORD | FIRST_DOC_ID | LAST_DOC_ID | DOC_COUNT | DOC_ID | POSITION |
+------------+--------------+-------------+-----------+--------+----------+
| 1001 | 5 | 5 | 1 | 5 | 0 |
| after | 3 | 3 | 1 | 3 | 22 |
| comparison | 6 | 6 | 1 | 6 | 44 |
| configured | 7 | 7 | 1 | 7 | 20 |
| database | 2 | 6 | 2 | 2 | 31 |
+------------+--------------+-------------+-----------+--------+----------+
INNODB_FT_INDEX_CACHE表现在是空的,因为OPTIMIZE table操作刷新了FULLTEXT索引缓存。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE LIMIT 5;
Empty set (0.00 sec)
从test/articles表中删除一些记录
mysql> DELETE FROM test.articles WHERE id < 4;
查询INNODB_FT_DELETED表。该表记录从FULLTEXT索引中删除的行。为了避免在DML操作期间进行昂贵的索引重组,有关新删除记录的信息被单独存储,在执行文本搜索时从搜索结果中过滤出来,在运行OPTIMIZE TABLE时从主搜索索引中删除。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DELETED;
+--------+
| DOC_ID |
+--------+
| 2 |
| 3 |
| 4 |
+--------+
OPTIMIZE TABLE articles;
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DELETED;
Empty set (0.00 sec)
optimize_checkpoint_limit:优化表运行超过的秒数。
synced_doc_id:下一个要发出的DOC_ID。
stopword_table_name:用户定义的停止词表的数据库/表名。如果没有用户定义的停用词表,VALUE列为空。
use_stopword:是否使用停止字表,在创建FULLTEXT索引时定义
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_CONFIG;
+---------------------------+-------+
| KEY | VALUE |
+---------------------------+-------+
| optimize_checkpoint_limit | 180 |
| synced_doc_id | 8 |
| stopword_table_name | |
| use_stopword | 1 |
+---------------------------+-------+
禁用innodb_optimize_fulltext_only,因为它只是暂时启用的
mysql> SET GLOBAL innodb_optimize_fulltext_only=OFF;
缓冲池表
INNODB_BUFFER_PAGE:保存InnoDB缓冲池中每个页面的信息。
INNODB_BUFFER_PAGE_LRU:保存了关于InnoDB缓冲池中页的信息,特别是它们在LRU列表中的排序方式,该列表决定了当缓冲池满时从缓冲池中清除哪些页。INNODB_BUFFER_PAGE_LRU表和INNODB_BUFFER_PAGE表有相同的列,不同的是INNODB_BUFFER_PAGE_LRU表有一个LRU_POSITION列而不是BLOCK_ID列。
INNODB_BUFFER_POOL_STATS:提供缓冲池状态信息。许多相同的信息是由SHOW ENGINE INNODB STATUS输出提供的,或者可以使用INNODB缓冲池服务器状态变量获得。
注意:查询INNODB_BUFFER_PAGE或INNODB_BUFFER_PAGE_LRU表可能会影响性能。不要在生产系统上查询这些表,除非您意识到性能影响并确定它是可接受的。为了避免影响生产系统的性能,请重现您想要调查的问题,并在测试实例上查询缓冲池统计信息。
示例4:查询系统数据
该查询通过排除TABLE_NAME值为NULL或包含斜杠/或句点的页面,提供了包含系统数据的页面的大致数量。表名,表示用户自定义表。
mysql> SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE TABLE_NAME IS NULL OR (INSTR(TABLE_NAME, '/') = 0 AND INSTR(TABLE_NAME, '.') = 0);
+----------+
| COUNT(*) |
+----------+
| 1516 |
+----------+
该查询返回包含系统数据的页面的大致数目、缓冲池页面的总数以及包含系统数据的页面的大致百分比。
SELECT
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE TABLE_NAME IS NULL OR (INSTR(TABLE_NAME, '/') = 0 AND INSTR(TABLE_NAME, '.') = 0)
) AS system_pages,
(
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
) AS total_pages,
(
SELECT ROUND((system_pages/total_pages) * 100)
) AS system_page_percentage;
+--------------+-------------+------------------------+
| system_pages | total_pages | system_page_percentage |
+--------------+-------------+------------------------+
| 295 | 8192 | 4 |
+--------------+-------------+------------------------+
可以通过查询PAGE_TYPE值来确定缓冲池中系统数据的类型。例如,下面的查询在包含系统数据的页面中返回8个不同的PAGE_TYPE值:
SELECT DISTINCT PAGE_TYPE FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE TABLE_NAME IS NULL OR (INSTR(TABLE_NAME, '/') = 0 AND INSTR(TABLE_NAME, '.') = 0);
+-------------------+
| PAGE_TYPE |
+-------------------+
| SYSTEM |
| IBUF_BITMAP |
| UNKNOWN |
| FILE_SPACE_HEADER |
| INODE |
| UNDO_LOG |
| ALLOCATED |
+-------------------+
示例5:查询用户数据
mysql> SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE TABLE_NAME IS NOT NULL AND TABLE_NAME NOT LIKE '%INNODB_TABLES%';
+----------+
| COUNT(*) |
+----------+
| 7897 |
+----------+
mysql> SELECT
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE TABLE_NAME IS NOT NULL AND (INSTR(TABLE_NAME, '/') > 0 OR INSTR(TABLE_NAME, '.') > 0)
) AS user_pages,
(
SELECT COUNT(*)
FROM information_schema.INNODB_BUFFER_PAGE
) AS total_pages,
(
SELECT ROUND((user_pages/total_pages) * 100)
) AS user_page_percentage;
+------------+-------------+----------------------+
| user_pages | total_pages | user_page_percentage |
+------------+-------------+----------------------+
| 7897 | 8192 | 96 |
+------------+-------------+----------------------+
这个查询将用户定义的表与缓冲池中的页面进行标识:
SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE TABLE_NAME IS NOT NULL AND (INSTR(TABLE_NAME, '/') > 0 OR INSTR(TABLE_NAME, '.') > 0)
AND TABLE_NAME NOT LIKE '`mysql`.`innodb_%';
+-------------------------+
| TABLE_NAME |
+-------------------------+
| `employees`.`salaries` |
| `employees`.`employees` |
+-------------------------+
示例6:查询索引数据
SELECT INDEX_NAME, COUNT(*) AS Pages,
ROUND(SUM(IF(COMPRESSED_SIZE = 0, @@GLOBAL.innodb_page_size, COMPRESSED_SIZE))/1024/1024)
AS 'Total Data (MB)'
FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE INDEX_NAME='emp_no' AND TABLE_NAME = '`employees`.`salaries`';
+------------+-------+-----------------+
| INDEX_NAME | Pages | Total Data (MB) |
+------------+-------+-----------------+
| emp_no | 1609 | 25 |
+------------+-------+-----------------+
SELECT INDEX_NAME, COUNT(*) AS Pages,
ROUND(SUM(IF(COMPRESSED_SIZE = 0, @@GLOBAL.innodb_page_size, COMPRESSED_SIZE))/1024/1024)
AS 'Total Data (MB)'
FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE TABLE_NAME = '`employees`.`salaries`'
GROUP BY INDEX_NAME;
+------------+-------+-----------------+
| INDEX_NAME | Pages | Total Data (MB) |
+------------+-------+-----------------+
| emp_no | 1608 | 25 |
| PRIMARY | 6086 | 95 |
+------------+-------+-----------------+
示例7:查询INNODB_BUFFER_PAGE_LRU表中的LRU_POSITION数据
SELECT COUNT(LRU_POSITION) FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE_LRU
WHERE TABLE_NAME='`employees`.`employees`' AND LRU_POSITION < 3072;
+---------------------+
| COUNT(LRU_POSITION) |
+---------------------+
| 548 |
+---------------------+
mysql> SELECT * FROM information_schema.INNODB_BUFFER_POOL_STATS \G
*************************** 1. row ***************************
POOL_ID: 0
POOL_SIZE: 8192
FREE_BUFFERS: 1
DATABASE_PAGES: 8173
OLD_DATABASE_PAGES: 3014
MODIFIED_DATABASE_PAGES: 0
PENDING_DECOMPRESS: 0
PENDING_READS: 0
PENDING_FLUSH_LRU: 0
PENDING_FLUSH_LIST: 0
PAGES_MADE_YOUNG: 15907
PAGES_NOT_MADE_YOUNG: 3803101
PAGES_MADE_YOUNG_RATE: 0
PAGES_MADE_NOT_YOUNG_RATE: 0
NUMBER_PAGES_READ: 3270
NUMBER_PAGES_CREATED: 13176
NUMBER_PAGES_WRITTEN: 15109
PAGES_READ_RATE: 0
PAGES_CREATE_RATE: 0
PAGES_WRITTEN_RATE: 0
NUMBER_PAGES_GET: 33069332
HIT_RATE: 0
YOUNG_MAKE_PER_THOUSAND_GETS: 0
NOT_YOUNG_MAKE_PER_THOUSAND_GETS: 0
NUMBER_PAGES_READ_AHEAD: 2713
NUMBER_READ_AHEAD_EVICTED: 0
READ_AHEAD_RATE: 0
READ_AHEAD_EVICTED_RATE: 0
LRU_IO_TOTAL: 0
度量表
INNODB_METRICS表提供了InnoDB性能和资源相关计数器的信息。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME="dml_inserts" \G
*************************** 1. row ***************************
NAME: dml_inserts
SUBSYSTEM: dml
COUNT: 46273
MAX_COUNT: 46273
MIN_COUNT: NULL
AVG_COUNT: 492.2659574468085
COUNT_RESET: 46273
MAX_COUNT_RESET: 46273
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
TIME_ENABLED: 2014-11-28 16:07:53
TIME_DISABLED: NULL
TIME_ELAPSED: 94
TIME_RESET: NULL
STATUS: enabled
TYPE: status_counter
COMMENT: Number of rows inserted
You can enable, disable, and reset counters using the following variables:
• innodb_monitor_enable: Enables counters.
SET GLOBAL innodb_monitor_enable = [counter-name|module_name|pattern|all];
• innodb_monitor_disable: Disables counters.
SET GLOBAL innodb_monitor_disable = [counter-name|module_name|pattern|all];
• innodb_monitor_reset: Resets counter values to zero.
SET GLOBAL innodb_monitor_reset = [counter-name|module_name|pattern|all];
• innodb_monitor_reset_all: Resets all counter values. A counter must be disabled before using
innodb_monitor_reset_all.
SET GLOBAL innodb_monitor_reset_all = [counter-name|module_name|pattern|all];
示例8:
这个例子演示了启用、禁用、重置计数器,以及查询INNODB_METRICS表中的计数器数据。
mysql> USE test;
Database changed
mysql> CREATE TABLE t1 (c1 INT) ENGINE=INNODB;
Query OK, 0 rows affected (0.02 sec)
Enable the dml_inserts counter
mysql> SET GLOBAL innodb_monitor_enable = dml_inserts;
Query OK, 0 rows affected (0.01 sec)
关于dml_inserts计数器的描述可以在INNODB_METRICS表的COMMENT列中找到:
mysql> SELECT NAME, COMMENT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME="dml_inserts";
+-------------+-------------------------+
| NAME | COMMENT |
+-------------+-------------------------+
| dml_inserts | Number of rows inserted |
+-------------+-------------------------+
查询INNODB_METRICS表中的dml_inserts计数器数据。因为没有执行DML操作,所以计数器值为零或NULL。TIME_ENABLED和TIME_ELAPSED值表示计数器上次启用的时间,以及从那次启用到现在已经过去了多少秒。
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME="dml_inserts" \G
*************************** 1. row ***************************
NAME: dml_inserts
SUBSYSTEM: dml
COUNT: 0
MAX_COUNT: 0
MIN_COUNT: NULL
AVG_COUNT: 0
COUNT_RESET: 0
MAX_COUNT_RESET: 0
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
TIME_ENABLED: 2014-12-04 14:18:28
TIME_DISABLED: NULL
TIME_ELAPSED: 28
TIME_RESET: NULL
STATUS: enabled
TYPE: status_counter
COMMENT: Number of rows inserted
mysql> INSERT INTO t1 values(1);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO t1 values(2);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO t1 values(3);
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME="dml_inserts"\G
*************************** 1. row ***************************
NAME: dml_inserts
SUBSYSTEM: dml
COUNT: 3
MAX_COUNT: 3
MIN_COUNT: NULL
AVG_COUNT: 0.046153846153846156
COUNT_RESET: 3
MAX_COUNT_RESET: 3
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
TIME_ENABLED: 2014-12-04 14:18:28
TIME_DISABLED: NULL
TIME_ELAPSED: 65
TIME_RESET: NULL
STATUS: enabled
TYPE: status_counter
COMMENT: Number of rows inserted
mysql> SET GLOBAL innodb_monitor_reset = dml_inserts;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME="dml_inserts"\G
*************************** 1. row ***************************
NAME: dml_inserts
SUBSYSTEM: dml
COUNT: 3
MAX_COUNT: 3
MIN_COUNT: NULL
AVG_COUNT: 0.03529411764705882
COUNT_RESET: 0
MAX_COUNT_RESET: 0
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: 0
TIME_ENABLED: 2014-12-04 14:18:28
TIME_DISABLED: NULL
TIME_ELAPSED: 85
TIME_RESET: 2014-12-04 14:19:44
STATUS: enabled
TYPE: status_counter
COMMENT: Number of rows inserted
mysql> SET GLOBAL innodb_monitor_disable = dml_inserts;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME="dml_inserts"\G
*************************** 1. row ***************************
NAME: dml_inserts
SUBSYSTEM: dml
COUNT: 3
MAX_COUNT: 3
MIN_COUNT: NULL
AVG_COUNT: 0.030612244897959183
COUNT_RESET: 0
MAX_COUNT_RESET: 0
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: 0
TIME_ENABLED: 2014-12-04 14:18:28
TIME_DISABLED: 2014-12-04 14:20:06
TIME_ELAPSED: 98
TIME_RESET: NULL
STATUS: disabled
TYPE: status_counter
COMMENT: Number of rows inserted
mysql> SET GLOBAL innodb_monitor_reset_all = dml_inserts;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME="dml_inserts"\G
*************************** 1. row ***************************
NAME: dml_inserts
SUBSYSTEM: dml
COUNT: 0
MAX_COUNT: NULL
MIN_COUNT: NULL
AVG_COUNT: NULL
COUNT_RESET: 0
MAX_COUNT_RESET: NULL
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
TIME_ENABLED: NULL
TIME_DISABLED: NULL
TIME_ELAPSED: NULL
TIME_RESET: NULL
STATUS: disabled
TYPE: status_counter
COMMENT: Number of rows inserted
临时表信息表
INNODB_TEMP_TABLE_INFO提供了用户创建的InnoDB临时表的信息,这些临时表在InnoDB实例中处于活动状态。它不提供有关优化器使用的内部InnoDB临时表的信息。
示例9:
mysql> CREATE TEMPORARY TABLE t1 (c1 INT PRIMARY KEY) ENGINE=INNODB;
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO\G
*************************** 1. row ***************************
TABLE_ID: 194
NAME: #sql7a79_1_0
N_COLS: 4
SPACE: 182
重启服务器然后查询INNODB_TEMP_TABLE_INFO.
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO\G
返回一个空集合,因为当服务器关闭时,INNODB_TEMP_TABLE_INFO及其数据不会被持久化到磁盘上。
返回一个空集合,因为当服务器关闭时,INNODB_TEMP_TABLE_INFO及其数据不会被持久化到磁盘上。
创建新的临时表
mysql> CREATE TEMPORARY TABLE t1 (c1 INT PRIMARY KEY) ENGINE=INNODB;
查询INNODB_TEMP_TABLE_INFO
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO\G
*************************** 1. row ***************************
TABLE_ID: 196
NAME: #sql7b0e_1_0
N_COLS: 4
SPACE: 184
SPACE ID可能会有所不同,因为它是在服务器启动时动态生成的。
INFORMATION_SCHEMA.FILES
表提供了所有InnoDB表空间类型的元数据,包括每个表文件的表空间、一般表空间、系统表空间、临时表空间和undo表空间(如果存在的话)
这个查询从INFORMATION_SCHEMA的字段中检索InnoDB系统表空间的元数据。与InnoDB表空间相关的FILES表。
INFORMATION_SCHEMA。与InnoDB无关的FILES字段总是返回NULL,并且被排除在查询之外。
mysql> SELECT FILE_ID, FILE_NAME, FILE_TYPE, TABLESPACE_NAME, FREE_EXTENTS,
TOTAL_EXTENTS, EXTENT_SIZE, INITIAL_SIZE, MAXIMUM_SIZE, AUTOEXTEND_SIZE, DATA_FREE, STATUS ENGINE
FROM INFORMATION_SCHEMA.FILES WHERE TABLESPACE_NAME LIKE 'innodb_system' \G
*************************** 1. row ***************************
FILE_ID: 0
FILE_NAME: ./ibdata1
FILE_TYPE: TABLESPACE
TABLESPACE_NAME: innodb_system
FREE_EXTENTS: 0
TOTAL_EXTENTS: 12
EXTENT_SIZE: 1048576
INITIAL_SIZE: 12582912
MAXIMUM_SIZE: NULL
AUTOEXTEND_SIZE: 67108864
DATA_FREE: 4194304
ENGINE: NORMAL
标签:COUNT,NAME,INNODB,mysql,InnoDB,TABLE,数据,SELECT,字典
From: https://blog.csdn.net/qq_29431123/article/details/141180762