mysql性能优化配置总结

  

,,,,

看了一些优化mysql运维的一些书籍,在此记录总结下:
进入mysql客户端输入以下sql:
1,连接设置

 show  variables  like “% max_connection %”;
  show  status  like  % Max_used_connections %的;

Max_used_connections/max_connection & lt;=85%,参数配置项的值可对照修改

2,存储在堆栈中的连接数量

 show  variables  like  % back_log %的;

back_log默认为50建议修改为128 ~ 512

3,数据连接关闭前等待时间

 show  variables  like  %超时%的;

修改interactive_timeout wait_timeout 2项的值,默认为,28800年建议修改为7200

索引缓冲区的大小

 show  status  like  %读取%的;

索引未缓存命中率key_read/key_request_reads ~=0.001 ~ 0.01

5,查询缓冲区的大小(query_cache_size)

 show  variables  like “%缓存%”;
  show  status  like  % qcache %的;

缓存碎片率Qcache_free_blocks/Qcache_total_blocks & lt; 20%
缓存利用率(query_cache_size-Qcache_free_memory)/query_cache_size<25%
缓存命中率Qcache_hits/Qcache_inserts> 95%

6,顺序读,随机读,排的序,连接缓冲区的大小,每个线程独占,建议设置为16 mb

 show  status  like  %缓冲%的;

read_buffer_size
read_rnd_buffer_size
sort_buffer_size
join_buffer_size

7、表缓冲区大小

 show  status  like  %表%的;

table_cache根据open_tables opented_tables大小来调整

8日内存表和临时表

 show  status  like  %表%,

max_heap_table_size
tmp_table_size
内存表超过临时表大小,才需要调整内存表的大小

9、磁盘上临时表大小

 show  status  like  % tmp %的;

(Created_tmp_disk_tables/Created_tmp_tables) * 100 & lt;

10 25%,缓存线程的数量

 show  variables  like  % tmp %的;

thread_cache_size

11、并发线程的数量

 show  variables  like  %线程%的;

innodb_thread_concurrency (cpu +磁盘)数量的2倍

12,其他
数据和索引缓冲区的大小通过innodb_buffer_pool_size物理内容的80%
日志缓冲区的大小innodb_log_buffer_size 1 ~ 8 mb
数据字段和其他数据结构的大小innodb_additional_mem_pool_size 20 mb
事物处理机制innodb_flush_log_at_trx_commit
0提交事物不写入日志,每秒日志文件写入和冲磁盘
每1秒或每次事物提交时,日志文件写入冲磁盘
2每次事物提交时,日志文件写入,每秒冲磁盘


mysql性能优化配置总结