MySQL 優化建議 (mysqltuner)

MySQL 優化建議 (mysqltuner)

MySQL 優化建議 (mysqltuner)

雖然現在有 chatGPT 很方便,但有時候會忘記,又要把狀況重新描述一次,

安裝這套,然後跑結果

wget http://mysqltuner.pl -O mysqltuner.pl
perl mysqltuner.pl

跑出來可能會類似這樣,不知道該怎麼辦的話,就把下面的 log 丟給 GPT,讓他幫你判斷吧。
要注意的是,不要一下就執行,最好先備份喔!

-------- Storage Engine Statistics -----------------------------------------------------------------
ℹ  Status: +ARCHIVE +Aria +BLACKHOLE +CSV +FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA 
ℹ  Data in MyISAM tables: 236.0M (Tables: 2)
ℹ  Data in InnoDB tables: 58.8M (Tables: 28)
✔  Total fragmented tables: 0
 
✘  Your MySQL version 5.5.68 is EOL software. Upgrade soon!
 
-------- Log file Recommendations ------------------------------------------------------------------
✔  Log file /var/log/mariadb/mariadb.log exists
ℹ  Log file: /var/log/mariadb/mariadb.log (238K)
✔  Log file /var/log/mariadb/mariadb.log is not empty
✔  Log file /var/log/mariadb/mariadb.log is smaller than 32 MB
✔  Log file /var/log/mariadb/mariadb.log is readable.
✘  /var/log/mariadb/mariadb.log contains 295 warning(s).
✘  /var/log/mariadb/mariadb.log contains 10 error(s).
ℹ  92 start(s) detected in /var/log/mariadb/mariadb.log
ℹ  1) 250921 14:51:33 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  2) 250917 15:00:52 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  3) 250313 23:42:18 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  4) 250226 22:35:29 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  5) 250209 13:47:15 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  6) 250209 13:45:34 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  7) 250209 13:44:24 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  8) 241211 21:57:35 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  9) 241202  9:05:14 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  10) 241117 23:37:47 [Note] /usr/libexec/mysqld: ready for connections.
ℹ  70 shutdown(s) detected in /var/log/mariadb/mariadb.log
ℹ  1) 250921 14:47:10 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  2) 250209 13:47:13 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  3) 250209 13:45:24 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  4) 250209 13:45:23 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  5) 250209 13:44:22 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  6) 241117 23:37:45 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  7) 240513  0:41:46 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  8) 231212 22:44:51 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  9) 231212  7:00:04 [Note] /usr/libexec/mysqld: Shutdown complete
ℹ  10) 230224  7:00:05 [Note] /usr/libexec/mysqld: Shutdown complete
 
-------- Analysis Performance Metrics --------------------------------------------------------------
ℹ  innodb_stats_on_metadata: ON
✘  Stat are updated during querying INFORMATION_SCHEMA.
 
-------- Views Metrics -----------------------------------------------------------------------------
 
-------- Triggers Metrics --------------------------------------------------------------------------
 
-------- Routines Metrics --------------------------------------------------------------------------
 
-------- Security Recommendations ------------------------------------------------------------------
ℹ  MariaDB Server - 5.5.68
✔  No Role user detected
✔  There are no anonymous accounts for any database users
✘  User ''example'@'localhost'' has no password set.
✘  There is no basic password file list!
 
-------- CVE Security Recommendations --------------------------------------------------------------
ℹ  Skipped due to --cvefile option undefined
 
-------- Performance Metrics -----------------------------------------------------------------------
ℹ  Up for: 4d 20h 51m 34s (817K q [1.944 qps], 88K conn, TX: 4G, RX: 82M)
ℹ  Reads / Writes: 49% / 51%
ℹ  Binary logging is disabled
ℹ  Physical Memory     : 3.6G
ℹ  Max MySQL memory    : 2.6G
ℹ  Other process memory: 0B
ℹ  Total buffers: 880.0M global + 8.3M per thread (214 max threads)
ℹ  Performance_schema Max memory usage: 0B
ℹ  Galera GCache Max memory usage: 0B
✔  Maximum reached memory usage: 1.0G (27.80% of installed RAM)
✔  Maximum possible memory usage: 2.6G (70.96% of installed RAM)
✔  Overall possible memory usage with other process is compatible with memory available
✔  Slow queries: 0% (81/817K)
✔  Highest usage of available connections: 8% (19/214)
✔  Aborted connections: 0.00% (2/88055)
✘  Query cache efficiency: 8.5% (21K cached / 249K selects)
✘  Query cache may be disabled by default due to mutex contention.
✔  Sorts requiring temporary tables: 0% (0 temp sorts / 47 sorts)
✔  No joins without indexes
✘  Temporary tables created on disk: 52% (1K on disk / 2K total)
✘  Thread cache is disabled
✔  Table cache hit rate: 88% (47 hits / 53 requests)
✔  table_definition_cache (65535) is greater than number of tables (133)
✔  Open file limit used: 2% (29/1K)
✔  Table locks acquired immediately: 95% (462K immediate / 481K locks)
 
-------- Performance schema ------------------------------------------------------------------------
✘  Performance_schema should be activated.
ℹ  Sys schema is not installed.
 
-------- ThreadPool Metrics ------------------------------------------------------------------------
ℹ  ThreadPool stat is disabled.
 
-------- MyISAM Metrics ----------------------------------------------------------------------------
✘  Consider migrating 2 following tables to InnoDB:
ℹ  * InnoDB migration request for `_example_snapshot`.`task` Table: ALTER TABLE `_example_snapshot`.`task` ENGINE=InnoDB;
ℹ  * InnoDB migration request for `example`.`task` Table: ALTER TABLE `example`.`task` ENGINE=InnoDB;
ℹ  General MyIsam metrics:
ℹ   +-- Total MyISAM Tables  : 2
ℹ   +-- Total MyISAM indexes : 354.0K
ℹ   +-- KB Size :64.0M
ℹ   +-- KB Used Size :11.8M
ℹ   +-- KB used :18.4%
ℹ   +-- Read KB hit rate: 100.0% (55M cached / 268 reads)
ℹ   +-- Write KB hit rate: 100.0% (92 cached / 92 writes)
✘  Key buffer used: 18.4% (11.8M used / 64.0M cache)
✔  Key buffer size / total MyISAM indexes: 64.0M/354.0K
✔  Read Key buffer hit rate: 100.0% (55M cached / 268 reads)
✔  Write Key buffer hit rate: 100.0% (92 cached / 92 writes)
 
-------- InnoDB Metrics ----------------------------------------------------------------------------
ℹ  InnoDB is enabled.
ℹ  InnoDB Thread Concurrency: 0
✔  InnoDB File per table is activated
✔  InnoDB Buffer Pool size ( 512.0M ) under limit for 64 bits architecture: (17179869184.0G )
✔  InnoDB buffer pool / data size: 512.0M / 58.8M
✘  Ratio InnoDB log file size / InnoDB Buffer pool size (1.953125%): 5.0M * 2 / 512.0M should be equal to 25%
✔  InnoDB buffer pool instances: 1
✘  Cannot calculate InnoDB Buffer Pool Chunk breakdown due to missing or zero values:
ℹ   - innodb_buffer_pool_size: 536870912
ℹ   - innodb_buffer_pool_chunk_size: undefined
ℹ   - innodb_buffer_pool_instances: 1
✔  InnoDB Read buffer efficiency: 100.00% (548154858 hits / 548156503 total)
✘  InnoDB Write Log efficiency: 77.23% (275450 hits / 356662 total)
✔  InnoDB log waits: 0.00% (0 waits / 81212 writes)
 
-------- Aria Metrics ------------------------------------------------------------------------------
ℹ  Aria Storage Engine is enabled.
✔  Aria pagecache size / total Aria indexes: 128.0M/0B
✘  Aria pagecache hit rate: 89.6% (13K cached / 1K reads)
 
-------- 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: STATEMENT
ℹ  XA support enabled: ON
ℹ  Semi synchronous replication Master: Not Activated
ℹ  Semi synchronous replication Slave: Not Activated
ℹ  This is a standalone server
 
-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    You are using an unsupported version for production environments
    Upgrade as soon as possible to a supported version !
    Check warning line(s) in /var/log/mariadb/mariadb.log file
    Check error line(s) in /var/log/mariadb/mariadb.log file
    Set up a Secure Password for 'example'@'localhost' user: SET PASSWORD FOR 'example'@'localhost' = PASSWORD('secure_password');
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries which have no LIMIT clause
    Set thread_cache_size to 4 as a starting value
    Performance schema should be activated for better diagnostics
    MyISAM engine is deprecated, consider migrating to InnoDB
    Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time
    For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB.
Variables to adjust:
    SET innodb_stats_on_metadata = OFF
    query_cache_limit (> 16M, or use smaller result sets)
    query_cache_size (=0)
    query_cache_type (=0)
    tmp_table_size (> 128M)
    max_heap_table_size (> 128M)
    thread_cache_size (start at 4)
    performance_schema=ON
    key_buffer_size (~ 12M)
    innodb_log_file_size should be (=64M) if possible, so InnoDB total log file size equals 25% of buffer pool size.
    innodb_log_buffer_size (> 32M)