简介
performance_schema是运行在较低级别的用于监控MySQL Server运行过程中的资源消耗、资源等待等情况的一个功能特性,也是一个存储引擎。该特性具有以下特点。
- 提供了一种在数据库运行时实时检查Server内部执行情况的方法
- 可监控任何事情以及对应的时间消耗,利用这些信息来判断Server中的相关资源消耗
- 只被记录在本地Server的performance_schema中,其表中数据发生变化时不会被写入binlog中,也不会通过复制机制被复制到其他Server中
- 对于这些表可使用SELECT语句查询,也可以使用SQL语句更新performance_schema数据库中的表记录,但不建议更新,会影响后续的数据收集
- 表中数据不会持久化存储在磁盘中,而是保存在内存中,一旦服务器重启,这些数据就会丢失
- 不会导致server的行为发生变化(查询,优化等)
- 总体上开销有限也不会影响性能
- 对某事件监测失败,不影响server正常运行
- 当针对一个数据,同时被performance_schema收集和查询,则收集优先与查询
- 事件监测点可进行配置
使用
- 查看是否当前数据库是否支持
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
Support为yes则表示支持该特性
- 查看该特性是否使能
mysql> show variables like 'performance_schema';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| performance_schema | ON |
+--------------------+-------+
1 row in set (0.02 sec)
如果为off则表示未使能。该参数为只读参数,则可在mysql.cnf中进行配置后重启服务
- 查看有哪些表使用了该引擎
mysql> use performance_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_performance_schema |
+------------------------------------------------------+
| accounts |
| binary_log_transaction_compression_stats |
| cond_instances |
| data_lock_waits |
| data_locks
-
使用该引擎的这些表的分类
通过查询,在mysql 8.0版本中,共有110个表。这些表根据监测维度不同,我们将其分为:
1)语句事件记录表
mysql> show tables like 'events_statement%';
+----------------------------------------------------+
| Tables_in_performance_schema (events_statement%) |
&#