MySQL性能优化之配置参数过程
1、连接设置
show variables like ‘%max_connection%'; show status like ‘%Max_used_connections%'; Max_used_connections/max_connection <=85%
2、存储在堆栈中的连接数量
show variables like ‘%back_log%';
back_log 默认为50 建议修改为 128~512
3、数据连接关闭前等待时间
show variables like ‘%timeout%';
修改interactive_timeout wait_timeout 2项的值,默认为28800,建议修改为7200
4、索引缓冲区的大小
show status like ‘%read%';
索引未缓存命中率 key_read/key_request_reads =0.0010.01
5、查询缓冲区的大小(query_cache_size)
show variables like ‘%cache%'; show status like ‘%qcache%';
- 缓存碎片率 Qcache_free_blocks/Qcache_total_blocks <20%
- 缓存利用率 (query_cache_size-Qcache_free_memory)/query_cache_size<25%
- 缓存命中率 Qcache_hits/Qcache_inserts>95%
6、顺序读、随机读、排序、连接缓冲区的大小,每个线程独占,建议设置为16MB
show status like ‘%buffer%'; read_buffer_size read_rnd_buffer_size sort_buffer_size join_buffer_size
7、表缓冲区大小
show status like ‘%tables%';
table_cache 根据 open_tables opented_tables 大小来调整
8、内存表和临时表
show status like ‘%table%'; max_heap_table_size tmp_table_size
内存表超过临时表大小,才需要调整内存表的大小
9、磁盘上临时表大小
show status like ‘%tmp%'; (Created_tmp_disk_tables/Created_tmp_tables)*100<25%
10、缓存线程的数量
show variables like ‘%tmp%'; thread_cache_size
11、并发线程的数量
show variables like ‘%thread%'; innodb_thread_concurrency (cpu+磁盘)数量的2倍
12、其他
数据和索引缓冲区的大小 innodb_buffer_pool_size 物理内容的80%
日志缓冲区的大小 innodb_log_buffer_size 1~8MB
数据字段和其他数据结构的大小 innodb_additional_mem_pool_size 20MB
事物处理机制 innodb_flush_log_at_trx_commit
- 0 提交事物不写入日志,每秒日志文件写入和flush磁盘
- 1 每秒或每次事物提交时,日志文件写入 flush磁盘
- 2 每次事物提交时,日志文件写入,每秒flush磁盘
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Spring Boot 3中一套可以直接用于生产环境的Log4J2日志配置详解
Log4J2是Apache Log4j的升级版,参考了logback的一些优秀的设计,并且修复了一些问题,因此带来了一些重大的提升,这篇文章主要介绍了Spring Boot 3中一套可以直接用于生产环境的Log4J2日志配置,需要的朋友可以参考下2023-12-12
关于SpringMVC在Controller层方法的参数解析详解
在SpringMVC中,控制器Controller负责处理由DispatcherServlet分发的请求,下面这篇文章主要给大家介绍了关于SpringMVC在Controller层方法的参数解析的相关资料,需要的朋友可以参考下2021-12-12
springboot+vue实现Token自动续期(双Token方案)
双Token方案通过访问令牌和刷新令牌提高用户登录安全性和体验,访问令牌有效期短,包含用户信息,用于请求校验,本文就来介绍一下springboot+vue实现Token自动续期(双Token方案),感兴趣的可以了解一下2024-10-10


最新评论