Mysql技能之【性能优化方案】

两个SHOW命令

  1. Mysql服务状态 SHOW GLOBAL STATUS;
  2. Mysql配置信息 SHOW VARIABLES;

慢查询

  1. show variables like '%slow%';
  2. show global status like '%slow%';

注:超过2s即为慢查询;可查看日志(variables会显示日志路径)

连接数

  1. show variables like 'max_connections';
  2. show global status like 'Max_used_connections';

注:最大连接数/连接上限应小于85%

关键缓冲区大小

  1. show variables like 'key_buffer_size';
  2. show global status like 'key_read%';
  3. show global status like 'key_block_u%';
注:这是一个很重要的指标,对索引影响很大;
1. key_buffer_size是分配的缓冲区大小,以字节为单位;
2. Key_reads_requests是索引读取请求个数;
3. Key_reads是没有在内存中找到直接在磁盘中找的索引数,这个数值越大,索引越慢

临时表大小

  1. show global status like 'created_tmp%';
  2. show variables where Variable_name in ('tmp_table_size','max_heap_table_size')
注:每次创建临时表,Created_tmp_tables会增加
1. Created_tmp_disk_tables是在磁盘上创建的临时表,占总的表Created_tmp_tables最好小于25%
2. max_heap_table_size最大临时表大小,超过部分会使用磁盘临时表

打开表的数量

  1. show global status like 'open%tables%';
  2. show variables like 'table_cache';

进程使用情况

  1. show global status like 'Thread%';
  2. show variables like 'thread_cache_size';

缓存使用情况

  1. show global status like 'qcache%';
  2. show variables like 'query_cache%';

文件打开数

  1. show gloabal status like 'open_files';
  2. show variables like 'open_files_limit';

表扫描情况

  1. show global status like 'handler_read%';
  2. show global status like 'com_select';

修改配置my.ini,my.conf

posted @ 2018-07-17 19:44  今天阳光那么好  阅读(196)  评论(0编辑  收藏  举报