Mysql
 sql >> Database >  >> RDS >> Mysql

Ottimizza le prestazioni di MySQL/MariaDB con lo strumento MySQLTunner

MySQLTunner è uno strumento Perl che ti assisterà e metterà a punto il tuo server di database MariaDB/MySQL. Controlla molti parametri del server, verifica password utente, verifica utenti anonimi, password non sicure (dove ad esempio la password è il nome utente), verifica vulnerabilità CVE note ecc.

Il primo passaggio per eseguire lo strumento è scaricare il file di script dal sito Web ufficiale https://github.com/major/MySQLTuner-perl

wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
wget https://github.com/major/MySQLTuner-perl/raw/master/vulnerabilities.csv

Il comando di base per eseguire lo script è:

perl mysqltuner.pl

Per verificare anche le vulnerabilità, devi scaricare il file vulnerabilities.csv ed eseguire il comando:

perl mysqltuner.pl --cvefile=vulnerabilities.csv

Un esempio dell'output da un server di prova:

[root@web /]# perl mysqltuner.pl --cvefile=vulnerabilities.csv

 >>  MySQLTuner 1.8.7 - Major Hayden <[email protected]>
 >>  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] Currently running supported MySQL version 10.6.5-MariaDB
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/log/mysqld.log exists
[--] Log file: /var/log/mysqld.log(69K)
[OK] Log file /var/log/mysqld.log is not empty
[OK] Log file /var/log/mysqld.log is smaller than 32 Mb
[OK] Log file /var/log/mysqld.log is readable.
[!!] /var/log/mysqld.log contains 394 warning(s).
[!!] /var/log/mysqld.log contains 49 error(s).
[--] 22 start(s) detected in /var/log/mysqld.log
[--] 1) 2022-01-08 16:04:41 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 2) 2022-01-04 12:20:12 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 3) 2021-12-27 17:21:20 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 4) 2021-12-11 15:39:01 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 5) 2021-12-11 14:47:28 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 6) 2021-12-11 14:47:22 0 [Note] /usr/sbin/mysqld: ready for connections.
-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in Aria tables: 32.0K (Tables: 1)
[--] Data in MEMORY tables: 0B (Tables: 40)
[--] Data in MyISAM tables: 1.3G (Tables: 34)
[--] Data in InnoDB tables: 217.2M (Tables: 31)
[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 ------------------------------------------------------------------
[OK] All database users have passwords assigned
-------- CVE Security Recommendations --------------------------------------------------------------
[OK] NO SECURITY CVE FOUND FOR YOUR VERSION

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 4d 19h 31m 2s (18M q [45.289 qps], 550K conn, TX: 53G, RX: 3G)
[--] Reads / Writes: 90% / 10%
[--] Binary logging is disabled
[--] Physical Memory     : 4.0G
[--] Max MySQL memory    : 38.3G
[--] Other process memory: 0B
[--] Total buffers: 305.0M global + 259.7M per thread (150 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Slow queries: 0% (33/18M)
[OK] Highest usage of available connections: 76% (114/150)
[OK] Aborted connections: 0.02%  (86/550353)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[OK] Query cache is disabled by default due to mutex contention on multiprocessor machines.
[OK] Sorts requiring temporary tables: 0% (227 temp sorts / 3M sorts)
[!!] Joins performed without indexes: 197183
[!!] Temporary tables created on disk: 56% (990K on disk / 1M total)
[OK] Thread cache hit rate: 99% (645 created / 550K connections)
[OK] Table cache hit rate: 95% (22M hits / 24M requests)
[OK] Open file limit used: 8% (1K/16K)
[OK] Table locks acquired immediately: 99% (17M immediate / 17M locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 2 thread(s).
[--] Using default value is good enough for your version (10.6.5-MariaDB)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 61.8% (9.9M used / 16.0M cache)
[OK] Key buffer size / total MyISAM indexes: 16.0M/152.4M
[OK] Read Key buffer hit rate: 100.0% (768M cached / 379K reads)
[!!] Write Key buffer hit rate: 54.4% (3M cached / 1M writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 128.0M/217.2M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 96.0M * 1/128.0M should be equal to 25%
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 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.98% (499634018 hits/ 499732161 total)
[!!] InnoDB Write Log efficiency: 270.94% (232636 hits/ 85863 total)
[OK] InnoDB log waits: 0.00% (0 waits / 318499 writes)

-------- Aria Metrics ------------------------------------------------------------------------------
[--] Aria Storage Engine is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/712.0K
[OK] Aria pagecache hit rate: 95.4% (18M cached / 860K 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: MIXED
[--] XA support enabled: ON
[--] Semi synchronous replication Master: OFF
[--] Semi synchronous replication Slave: OFF
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Check warning line(s) in /var/log/mysqld.log file
    Check error line(s) in /var/log/mysqld.log file
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    We will suggest raising the 'join_buffer_size' until JOINs not using indexes are found.
             See https://dev.mysql.com/doc/internals/en/join-buffer-size.html
             (specially the conclusions at the bottom of the page).
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries which have no LIMIT clause
    Performance schema should be activated for better diagnostics
    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 ***
    join_buffer_size (> 1.0M, or always use indexes with JOINs)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    performance_schema = ON enable PFS
    key_buffer_size (~ 10M)

Controlla attentamente le Raccomandazioni sezione e intraprendere le azioni necessarie. Le opzioni MySQL/MariaDB sono memorizzate nel file /etc/my.cnf. Puoi modificare questo file con un editor come vi o nano:

nano /etc/my.cnf

Alla fine, salva il file e riavvia il server MySQL:

service mysqld restart