Mysql

如何調試意外的mysqld重啟?

  • July 30, 2022

我正在使用 Apache、PHP 和 MySQL (8.1.6) 執行 DigitalOcean droplet。MySQL 今天早上意外重啟,連續兩次,在最小負載下。

我如何確定可能導致此問題的原因?之前的錯誤日誌都是gzip壓縮的並且是空的(這正常嗎?)。發生這種情況時,我沒有通過 SSH 連接到伺服器,所以這不是我做的事情。

這是/var/log/mysql/error.log顯示兩次關閉的全部內容。

022-07-30T13:24:00.952736Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.29-0ubuntu0.20.04.3).             
2022-07-30T13:24:08.863447Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29-0ubuntu0.20.04.3)  (Ubuntu).
2022-07-30T13:24:13.726982Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30-0ubuntu0.20.04.2) starting as process 2365053
2022-07-30T13:24:13.753328Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-30T13:24:14.472300Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-30T13:24:20.421561Z 4 [System] [MY-013381] [Server] Server upgrade from '80029' to '80030' started.
2022-07-30T13:24:32.733700Z 4 [System] [MY-013381] [Server] Server upgrade from '80029' to '80030' completed.
2022-07-30T13:24:32.998287Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-30T13:24:32.998440Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-30T13:24:33.001764Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/tmp' in the path is accessible to all OS users. Consider choosing a different directory.
2022-07-30T13:24:33.022249Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2022-07-30T13:24:33.022457Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30-0ubuntu0.20.04.2'  socket: '/tmp/tmp.vbQx6rn6ge/mysqld.sock'  port: 0  (Ubuntu).
2022-07-30T13:24:33.067042Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.30-0ubuntu0.20.04.2).
2022-07-30T13:24:35.232251Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30-0ubuntu0.20.04.2)  (Ubuntu).
2022-07-30T13:24:37.572513Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30-0ubuntu0.20.04.2) starting as process 2365514
2022-07-30T13:24:37.582988Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-30T13:24:38.082993Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-30T13:24:38.322802Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-30T13:24:38.322844Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-30T13:24:38.356500Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2022-07-30T13:24:38.356615Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30-0ubuntu0.20.04.2'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  (Ubuntu).

此外,mysqltuner.py 的輸出:

>>  MySQLTuner 2.0.1
        * Jean-Marie Renouard <jmrenouard@gmail.com>
        * Major Hayden <major@mhtx.net>
>>  Bug reports, feature requests, and downloads at http://mysqltuner.pl/
>>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials from Debian maintenance account.
[OK] Currently running supported MySQL version 8.0.30-0ubuntu0.20.04.2
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/log/mysql/error.log exists
[--] Log file: /var/log/mysql/error.log (2K)
[OK] Log file /var/log/mysql/error.log is not empty
[OK] Log file /var/log/mysql/error.log is smaller than 32 Mb
[OK] Log file /var/log/mysql/error.log is readable.
[!!] /var/log/mysql/error.log contains 3 warning(s).
[OK] /var/log/mysql/error.log doesn't contain any error.
[--] 4 start(s) detected in /var/log/mysql/error.log
[--] 1) 2022-07-30T13:24:38.356615Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30-0ubuntu0.20.04.2'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  (Ubuntu).
[--] 2) 2022-07-30T13:24:38.356500Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
[--] 3) 2022-07-30T13:24:33.022457Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30-0ubuntu0.20.04.2'  socket: '/tmp/tmp.vbQx6rn6ge/mysqld.sock'  port: 0  (Ubuntu).
[--] 4) 2022-07-30T13:24:33.022249Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
[--] 2 shutdown(s) detected in /var/log/mysql/error.log
[--] 1) 2022-07-30T13:24:35.232251Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30-0ubuntu0.20.04.2)  (Ubuntu).
[--] 2) 2022-07-30T13:24:08.863447Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29-0ubuntu0.20.04.3)  (Ubuntu).

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA 
[--] Data in InnoDB tables: 1.5G (Tables: 48)
[--] Data in MyISAM tables: 6.1M (Tables: 6)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Views Metrics -----------------------------------------------------------------------------

-------- Triggers Metrics --------------------------------------------------------------------------

-------- Routines Metrics --------------------------------------------------------------------------

-------- Security Recommendations ------------------------------------------------------------------
[--] Skipped due to unsupported feature for MySQL 8

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 2h 45m 29s (1M q [103.514 qps], 116K conn, TX: 4G, RX: 214M)
[--] Reads / Writes: 49% / 51%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Physical Memory     : 7.8G
[--] Max MySQL memory    : 11.8G
[--] Other process memory: 0B
[--] Total buffers: 2.0G global + 65.9M per thread (151 max threads)
[--] P_S Max memory usage: 72B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 2.4G (31.31% of installed RAM)
[!!] Maximum possible memory usage: 11.8G (151.35% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (50/1M)
[OK] Highest usage of available connections: 3% (6/151)
[OK] Aborted connections: 0.00%  (0/116975)
[--] Skipped name resolution test due to skip_networking=ON in system variables.
[--] Query cache have been removed in MySQL 8
[!!] Sorts requiring temporary tables: 20% (597 temp sorts / 2K sorts)
[OK] No joins without indexes
[OK] Temporary tables created on disk: 0% (0 on disk / 162 total)
[OK] Thread cache hit rate: 99% (6 created / 116K connections)
[OK] Table cache hit rate: 99% (952K hits / 953K requests)
[OK] table_definition_cache (2000) is greater than number of tables (394)
[OK] Open file limit used: 0% (28/10K)
[OK] Table locks acquired immediately: 99% (1K immediate / 1K locks)
[OK] Binlog cache memory access: 100.00% (456184 Memory / 456184 Total)

-------- Performance schema ------------------------------------------------------------------------
[--] Performance_schema is activated.
[--] Memory used by P_S: 72B
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[--] MyISAM Metrics are disabled on last MySQL versions.

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 2.0G/1.5G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (4.6875%): 48.0M * 2/2.0G should be equal to 25%
[!!] InnoDB buffer pool instances: 8
[--] Number of InnoDB Buffer Pool Chunk: 16 for 8 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.95% (135494768 hits/ 135565036 total)
[!!] InnoDB Write Log efficiency: 72.11% (3489529 hits/ 4839323 total)
[OK] InnoDB log waits: 0.00% (0 waits / 1349794 writes)

-------- Aria Metrics ------------------------------------------------------------------------------
[--] Aria Storage Engine not available.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: ROW
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
   Check warning line(s) in /var/log/mysql/error.log file
   MySQL was started within the last 24 hours - recommendations may be inaccurate
   Reduce your overall MySQL memory footprint for system stability
   Dedicate this server to your database for highest performance.
   Buffer Key MyISAM set to 0, no MyISAM table detected
   Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
Variables to adjust:
 *** MySQL's maximum memory usage is dangerously high ***
 *** Add RAM before increasing MySQL buffer variables ***
   sort_buffer_size (> 256K)
   read_rnd_buffer_size (> 256K)
   key_buffer_size=0
   innodb_log_file_size should be (=256M) if possible, so InnoDB total log files size equals 25% of buffer pool size.
   innodb_buffer_pool_instances(=2)

我知道它警告說最大理論記憶體使用量太高,但它不可能達到這一點——而且我的 DigitalOcean 圖表無論如何都沒有顯示 RAM 峰值。

任何故障排除幫助將不勝感激!

在發布的錯誤日誌中觀察,

auto update from 8.0.29 
to
8.0.30

經 MySQLTuner 報告 2h-45m 確認。

合理的結論?

引用自:https://serverfault.com/questions/1107024