一:Performance Schema的开启
在mysql中新增了一个性能优化的引擎,在mysql5.6.6之前Performance Schema是默认关闭的,在Mysql5.6.6之后Performance Schema默认是开启的。所以mysql5.6.6之前的版本要使用Performance Schema需要用手工开启,首先输入命令查看当前数据库中performance schema的开启情况。
首先在dos命令窗口输入以下命令:
mysqld --verbose --help
performance-schema FALSE
performance-schema-events-waits-history-long-size 10000
performance-schema-events-waits-history-size 10
performance-schema-max-cond-classes 80
performance-schema-max-cond-instances 1000
performance-schema-max-file-classes 50
performance-schema-max-file-handles 32768
performance-schema-max-file-instances 10000
performance-schema-max-mutex-classes 200
performance-schema-max-mutex-instances 1000000
performance-schema-max-rwlock-classes 30
performance-schema-max-rwlock-instances 1000000
performance-schema-max-table-handles 100000
performance-schema-max-table-instances 50000
performance-schema-max-thread-classes 50
performance-schema-max-thread-instances 1000
然后在my.ini配置文件中输入以下内容,开启performance_schema参数
[mysqld]
performance_schema=on
然后重启mysql服务.在用命令查看,如下:
二:Performance Schema的深入了解
在mysql的命令窗口输入图片中的命令,看看有什么,看以下命令截图:
这里的数据表分为几类:
1、 setup table : 设置表,配置监控选项。
2、 current events table : 记录当前那些thread 正在发生什么事情。
3、 history table 发生的各种事件的历史记录表
4、 summary table 对各种事件的统计表
5、 杂项表。
三、setup 表的说明
mysql_Performance Schema_setup 表 setup_consumers 描述各种事件 setup_instruments 描述这个数据库下的表名以及是否开启监控。 setup_timers 描述 监控选项已经采样频率的时间间隔
mysql> SELECT * FROM setup_timers;
+-----------+-------------+
| NAME | TIMER_NAME |
+-----------+-------------+
| idle | MICROSECOND |
| wait | CYCLE |
| stage | NANOSECOND |
| statement | NANOSECOND |
+-----------+-------------+
这个要多说一点 目前 performance-schema 只支持 'wait' 时间的监控,代码树上 wait/ 下的函数都可以监控到。
四、性能事件表
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'performance_schema'
AND TABLE_NAME LIKE '%current';
记录当前正在发生的等待事件,这个表是只读的表,不能update ,delete ,但是可以truncate
五、性能历史表
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'performance_schema'
AND (TABLE_NAME LIKE '%history' OR TABLE_NAME LIKE '%history_long');
这些表与前面的性能表的结构是一致的, history 表只保留每个线程(thread) 的最近的10个事件, history_long 记录最近的10000个事件。
新事件如表,如果旧表满了,就会丢弃旧的数据,标准的先进先出(FIFO) 这俩表也是只读表,只能truncate
六、事件汇总表
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'performance_schema'
AND TABLE_NAME LIKE '%summary%';
按照相关的标准对进行的事件统计表,events_waits_summary_global_by_event_name, 在mysql5.5.7 以前叫: EVENTS_WAITS_SUMMARY_BY_EVENT_NAME表也是只读的,只能turcate
七、性能优化实例(performance schema instance) 表
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'performance_schema'
AND TABLE_NAME LIKE '%instances';
记录各种等待事件涉及到的实例,主要是3类: cond (容器) mutex (互斥锁) ,rwlock (读写锁)这表是只读的。
八、performance_timers 表
SELECT * FROM performance_timers;
这个表式只读表,记录了事件采样频率的设定,我们前面说的setup_timer 表的timer_name 只能是这几个中一个。
九、performance_schema的各个系统参数
SHOW VARIABLES LIKE 'perf%';
涉及到系统状态的参数:
SHOW STATUS LIKE 'perf%';
mysql_performance_schema系统状态的参数