数据库性能下降,升级到MySQL 8.0.20后
在将MySQL从5.7版升级到8.0版后,我发现数据库性能显著下降 在升级MySQL之前,CPU使用率稳定在30%+-,但升级之后,CPU使用率变得不稳定,经常出现大峰值 最近我测试了一些非常有趣的东西,我一直在运行一个相同的查询,结果发现所花费的时间越来越长。如下图所示 我读了很多文章和堆栈溢出帖子,但没有一个解决方案是真正得到帮助。 所以希望有人能和我分享一些关于调整MySQL8.0的想法或经验 我会非常感激的 请让我知道,如果需要进一步调查的任何信息 配置my.ini:-数据库性能下降,升级到MySQL 8.0.20后,mysql,mysql-8.0,Mysql,Mysql 8.0,在将MySQL从5.7版升级到8.0版后,我发现数据库性能显著下降 在升级MySQL之前,CPU使用率稳定在30%+-,但升级之后,CPU使用率变得不稳定,经常出现大峰值 最近我测试了一些非常有趣的东西,我一直在运行一个相同的查询,结果发现所花费的时间越来越长。如下图所示 我读了很多文章和堆栈溢出帖子,但没有一个解决方案是真正得到帮助。 所以希望有人能和我分享一些关于调整MySQL8.0的想法或经验 我会非常感激的 请让我知道,如果需要进一步调查的任何信息 配置my.ini:- key_buf
key_buffer_size = 2G
max_allowed_packet = 1M
;Added to reduce memory used (minimum is 400)
table_definition_cache = 600
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 2M
read_rnd_buffer_size = 2M
myisam_sort_buffer_size = 2G
;Path to mysql install directory
basedir="c:/wamp64/bin/mysql/mysql8.0.20"
log-error="c:/wamp64/logs/mysql.log"
;Verbosity Value 1 Errors only, 2 Errors and warnings , 3 Errors, warnings, and notes
log_error_verbosity=2
;Path to data directory
datadir="c:/wamp64/bin/mysql/mysql8.0.20/data"
;slow_query_log = ON
;slow_query_log_file = "c:/wamp64/logs/slow_query.log"
;Path to the language
;See Documentation:
; http://dev.mysql.com/doc/refman/5.7/en/error-message-language.html
lc-messages-dir="c:/wamp64/bin/mysql/mysql8.0.20/share"
lc-messages=en_US
; The default storage engine that will be used when create new tables
default-storage-engine=InnoDB
; New for MySQL 5.6 default_tmp_storage_engine if skip-innodb enable
; default_tmp_storage_engine=MYISAM
;To avoid warning messages
secure_file_priv="c:/wamp64/tmp"
skip-ssl
explicit_defaults_for_timestamp=true
; Set the SQL mode to strict
sql-mode=""
;sql-mode="STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER"
;skip-networking
; Disable Federated by default
skip-federated
; Replication Master Server (default)
; binary logging is required for replication
;log-bin=mysql-bin
; binary logging format - mixed recommended
;binlog_format=mixed
; required unique id between 1 and 2^32 - 1
; defaults to 1 if master-host is not set
; but will not function as a master if omitted
server-id = 1
; Replication Slave (comment out master section to use this)
; New for MySQL 5.6 if no slave
skip-slave-start
; The InnoDB tablespace encryption feature relies on the keyring_file
; plugin for encryption key management, and the keyring_file plugin
; must be loaded prior to storage engine initialization to facilitate
; InnoDB recovery for encrypted tables. If you do not want to load the
; keyring_file plugin at server startup, specify an empty string.
early-plugin-load=""
;innodb_data_home_dir = C:/mysql/data/
innodb_data_file_path = ibdata1:12M:autoextend
;innodb_log_group_home_dir = C:/mysql/data/
;innodb_log_arch_dir = C:/mysql/data/
; You can set .._buffer_pool_size up to 50 - 80 %
; of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 4G
; Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 16M
innodb_log_buffer_size = 8M
innodb_thread_concurrency = 64
innodb_flush_log_at_trx_commit = 2
log_bin_trust_function_creators = 1;
innodb_lock_wait_timeout = 120
innodb_flush_method=normal
innodb_use_native_aio = true
innodb_flush_neighbors = 2
innodb_autoinc_lock_mode = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
; Remove the next comment character if you are not familiar with SQL
;safe-updates
[isamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer_size = 2M
write_buffer_size = 2M
[myisamchk]
key_buffer_size = 256M ;20M hys
sort_buffer_size_size = 20M
read_buffer_size = 2M
write_buffer_size = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld]
port = 3306
skip-log-bin
default_authentication_plugin= mysql_native_password
max_connections = 400
max_connect_errors = 100000
innodb_read_io_threads = 32
innodb_write_io_threads = 8
innodb_thread_concurrency = 64
硬件:-
内存:16GB
CPU:4核3.0 Ghz
显示全局状态:
显示引擎INNODB状态:
显示全局变量:
[更新:在我们的网站上解决了问题] 事实上,我现在有一个非常类似的问题(也许是相同的?)。 我们有
- Windows Server 2016,4个CPU,32 GB RAM
- MySQL 8社区版
- 基于Java/ApacheTomcat的顶层应用程序
- 备份应用程序架构(使用mysqldump命令)
- 手动安装MySQL 8.0.18二进制文件(无安装程序)
- 创建了一个额外的MySQL实例(不同的,不同的端口)
- 将备份导入新实例(使用mysql命令)
- 创建的角色和权限与“之前”完全相同
- 将应用程序配置切换到新的MySQL端口
innodb_lru_scan_depth=100 # from 1024 to conserve 90% of CPU cycles used for function
key_buffer_size=16M # from 1G to conserve RAM - you are not using MyISAM data tables
read_rnd_buffer_size=64K # from 2M to reduce handler_read_rnd_next RPS of 1,872,921
innodb_io_capacity=900 # from 200 to more of your rotating drive IOPS capacity
您应该发现这些更改减少了查询完成时间和CPU繁忙时间
select_扫描平均值为41 RPM,这是由于索引不可用导致的延迟
有关其他建议,请查看个人资料、网络个人资料以获取联系信息、常见问题解答、其他提示和免费下载的实用程序脚本,以帮助进行性能调整。我已找到根本原因,并将其发布在中
非常感谢您的回复和建议。非常感谢。如果您希望改进特定查询,请为查询中的每个表包括
showcreatetable{tablename}
,以及EXPLAIN{query}
。dba.stackexchange.com/将是一个更好的论坛。要进行调优,请包括完整的my.ini/cnf配置、硬件RAM/CPU和显示全局状态
(可能作为外部链接)和显示引擎INNODB状态
。欢迎使用stackoverflow。还请-在正常运行24小时后,在pastebin.com上发布(并共享链接)显示全局变量的文本结果;用于工作量分析。您的数据存储有SSD或NVME吗?@danblack我想改进的是数据库的整体性能,查询已经在MySQL 5.7中进行了微调。稍后我将在这里更新这些配置、硬件等。谢谢你的建议,也很抱歉语法不好。@WilsonHauck,据我的服务器管理员所知,我们目前正在使用普通硬盘。谢谢你显示全局状态;还请将显示全局变量的文本结果发布到pastebin.com;并共享链接以允许工作负载分析。这并不能真正回答问题。如果您有不同的问题,可以单击以提问。一旦你有足够的时间,你也可以吸引更多的注意力@user13860786,刚才我已经测试过安装MySQL 8.0.21,但问题似乎仍然存在。稍后我也会尝试MySQL 8.0.18,希望它真的是由“bug”引起的。顺便说一下,我也看到了这一点,并测试了提供的临时解决方案,但它不起作用。您是如何解决这一问题的?我现在也有同样的问题。谢谢你的建议,将考虑那些设置到我的系统配置。
innodb_lru_scan_depth=100 # from 1024 to conserve 90% of CPU cycles used for function
key_buffer_size=16M # from 1G to conserve RAM - you are not using MyISAM data tables
read_rnd_buffer_size=64K # from 2M to reduce handler_read_rnd_next RPS of 1,872,921
innodb_io_capacity=900 # from 200 to more of your rotating drive IOPS capacity