簡體   English   中英

數據庫性能下降,升級到 MySQL 8.0.20 后

[英]Database performance drop, after upgrade to MySQL 8.0.20

將MySQL從5.7升級到8.0后,發現數據庫性能明顯下降。

MySQL升級前CPU使用率穩定在30%+-左右,升級后CPU使用率不穩定,經常出現大的尖峰。

最近我測試了一些非常有趣的東西,我一直運行相同的查詢幾次,發現所用的持續時間越來越長。 如下圖所示。

在此處輸入圖像描述

我已經閱讀了很多文章和堆棧溢出帖子,但沒有一個解決方案是真正得到幫助的。 所以希望有人能和我分享一些調優MySQL8.0的想法或經驗。

將非常感激。

如果需要任何信息以進行進一步調查,請告訴我。

配置 my.ini:-

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

顯示全球狀態: https://pastebin.com/FVZrgnTw

顯示引擎 INNODB 狀態: https://pastebin.com/Rewp84Gi

顯示全局變量: https://pastebin.com/3v6cM6KZ

每秒速率 = RPS

為您的 my.ini [mysqld] 部分考慮的建議 在 my.ini 配置中有超過 1 個 [mysqld] 部分是不常見的,您在 my.ini 末尾附近的部分可以移動到 [ mysqldump] 以避免混淆。

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_scan 平均 41 RPS 並且是由索引不可用引起的,從而導致延遲。

有關其他建議,請查看配置文件、聯系信息的網絡配置文件、常見問題解答、其他提示和免費下載的實用程序腳本,以幫助進行性能調整。

我找到了根本原因,並將其發布在https://dba.stackexchange.com/questions/271785/query-performance-become-slower-after-upgrade-to-mysql-8-0-20中。

非常感謝大家的回復和建議。 欣賞它。

[更新:解決了我們網站的問題]

其實我目前有有一個非常相似(也許相同?)的問題。 我們有

  • Windows 服務器 2016,4 個 CPU,32 GB RAM
  • MySQL 8 社區版
  • Java / Apache Tomcat 基於頂部的應用程序

兩周來,我們遇到了嚴重的應用程序問題,一旦應用程序交互發生,mysqld 進程就占用了 100% 的 CPU——導致服務器完全沒有響應。

由於安全修復,在此降級之前對設置的最后一次更改是將 MySQL 從 8.0.18 更新到 8.0.20。

查詢監控顯示相同(簡單)查詢的多次出現

SELECT COUNT(1) FROM xxxxx;

這需要 5-10 秒(雖然表只有大約 3 行,所以它應該需要 5 毫秒。)。

One hypothesis was this MySQL issue: https://bugs.mysql.com/bug.php?id=99593 However the recommended workaround did not help me.

我們的解決方案:

顯然,在 8.0.19 或 8.0.20 中引入的 MySQL 社區版中存在一個額外的錯誤。 將 MySQL 降級到 8.0.18 后一切正常!

附加說明:

MySQL 不支持降級,實際上是為了在同一台機器上提供降級的DB。 我...

  • 做了應用程序模式的備份(使用 mysqldump 命令)
  • 手動安裝了 MySQL 8.0.18 二進制文件(無安裝程序)
  • 創建了一個額外的 MySQL 實例(不同的數據目錄,不同的端口)
  • 將備份導入新實例(使用 mysql 命令)
  • 創建的角色和權限與“之前”完全相同
  • 將應用程序配置切換到新的 MySQL 端口

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM