主要用于对mysql配置及my.cnf配置检查,提供详细信息,为进一步优化mysql做参考。
下载地址:
(2)脚本获取
# wget -c https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
(3)脚本执行
# chmod +x mysqltuner.pl
# ./mysqltuner.pl
[root@node2 ~]# perl mysqltuner.pl
>> MySQLTuner 1.7.9 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[--] Skipped version check for MySQLTuner script
Please enter your MySQL administrative login: andyhsi
Please enter your MySQL administrative password: [!!] Attempted to use login credentials, but they were invalid.
[root@node2 ~]# perl mysqltuner.pl -S /tmp/mysql3306.sock
Option s is ambiguous (silent, skippassword, skipsize, socket, ssl-ca, sysstat)
Name:
MySQLTuner 1.7.9 - MySQL High Performance Tuning Script
Important Usage Guidelines:
To run the script with the default options, run the script without
arguments Allow MySQL server to run for at least 24-48 hours before
trusting suggestions Some routines may require root level privileges
(script will provide warnings) You must provide the remote server's
total memory when connecting to other servers
Connection and Authentication:
--host <hostname> Connect to a remote host to perform tests (default: localhost)
--socket <socket> Use a different socket for a local connection
--port <port> Port to use for connection (default: 3306)
--user <username> Username to use for authentication
--userenv <envvar> Name of env variable which contains username to use for authentication
--pass <password> Password to use for authentication
--passenv <envvar> Name of env variable which contains password to use for authentication
--ssl-ca <path> Path to public key
--mysqladmin <path> Path to a custom mysqladmin executable
--mysqlcmd <path> Path to a custom mysql executable
--defaults-file <path> Path to a custom .my.cnf
Performance and Reporting Options:
--skipsize Don't enumerate tables and their types/sizes (default: on)
(Recommended for servers with many tables)
--skippassword Don't perform checks on user passwords(default: off)
--checkversion Check for updates to MySQLTuner (default: don't check)
--updateversion Check for updates to MySQLTuner and update when newer version is available (default: don't check)
--forcemem <size> Amount of RAM installed in megabytes
--forceswap <size> Amount of swap memory configured in megabytes
--passwordfile <path> Path to a password file list(one password by line)
Output Options:
--silent Don't output anything on screen
--nogood Remove OK responses
--nobad Remove negative/suggestion responses
--noinfo Remove informational responses
--debug Print debug information
--dbstat Print database information
--idxstat Print index information
--sysstat Print system information
--pfstat Print Performance schema
--bannedports Ports banned separated by comma(,)
--maxportallowed Number of ports opened allowed on this hosts
--cvefile <path> CVE File for vulnerability checks
--nocolor Don't print output in color
--json Print result as JSON string
--buffers Print global and per-thread buffer values
--outputfile <path> Path to a output txt file
--reportfile <path> Path to a report txt file
--template <path> Path to a template file
--verbose Prints out all options (default: no verbose)
++++++++++++++++++++++++++++++++++++++以上是参数+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
执行结果如下:
[root@node2 ~]# perl mysqltuner.pl --socket /tmp/mysql3306.sock
>> MySQLTuner 1.7.9 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[--] Skipped version check for MySQLTuner script
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password:
[OK] Currently running supported MySQL version 5.7.22-log
[OK] Operating on 64-bit architecture
-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: /data/mysql/mysql3306/logs/error.log(108K)
[OK] Log file /data/mysql/mysql3306/logs/error.log exists
[OK] Log file /data/mysql/mysql3306/logs/error.log is readable.
[OK] Log file /data/mysql/mysql3306/logs/error.log is not empty
[OK] Log file /data/mysql/mysql3306/logs/error.log is smaller than 32 Mb
[!!] /data/mysql/mysql3306/logs/error.log contains 34 warning(s).
[!!] /data/mysql/mysql3306/logs/error.log contains 130 error(s).
[--] 0 start(s) detected in /data/mysql/mysql3306/logs/error.log
[--] 0 shutdown(s) detected in /data/mysql/mysql3306/logs/error.log
-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in InnoDB tables: 16.0K (Tables: 1)
[OK] Total fragmented tables: 0
-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] There is no basic password file list!
-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined
-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 6m 38s (16 q [0.040 qps], 10 conn, TX: 44K, RX: 1K)
[--] Reads / Writes: 100% / 0%
[--] Binary logging is enabled (GTID MODE: ON)
[--] Physical Memory : 974.6M
[--] Max MySQL memory : 1.3G
[--] Other process memory: 92.8M
[--] Total buffers: 253.0M global + 1.1M per thread (1000 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 254.1M (26.08% of installed RAM)
[!!] Maximum possible memory usage: 1.3G (141.40% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/16)
[OK] Highest usage of available connections: 0% (1/1000)
[!!] Aborted connections: 10.00% (1/10)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 6 selects)
[OK] Query cache prunes per day: 0
[OK] No Sort requiring temporary tables
[OK] No joins without indexes
[OK] Temporary tables created on disk: 0% (0 on disk / 4 total)
[OK] Thread cache hit rate: 90% (1 created / 10 connections)
[OK] Table cache hit rate: 93% (105 open / 112 opened)
[OK] Open file limit used: 0% (20/164K)
[OK] Table locks acquired immediately: 100% (102 immediate / 102 locks)
[OK] Binlog cache memory access: 0% (0 Memory / 0 Total)
-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema is installed.
-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.
-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.3% (1M used / 8M cache)
[OK] Key buffer size / total MyISAM indexes: 8.0M/43.0K
[!!] Read Key buffer hit rate: 50.0% (6 cached / 3 reads)
-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 100.0M/16.0K
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (300 %): 100.0M * 3/100.0M should be equal 25%
[OK] InnoDB buffer pool instances: 1
[--] 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
[!!] InnoDB Read buffer efficiency: 79.80% (1015 hits/ 1272 total)
[!!] InnoDB Write Log efficiency: 200% (4 hits/ 2 total)
[OK] InnoDB log waits: 0.00% (0 waits / 6 writes)
-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.
-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.
-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.
-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.
-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.
-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect 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 replication slave is not running but seems to be configured.
-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Control warning line(s) into /data/mysql/mysql3306/logs/error.log file
Control error line(s) into /data/mysql/mysql3306/logs/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.
Reduce or eliminate unclosed connections and network issues
Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
Performance schema should be activated for better diagnostics
Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: http://bit.ly/2wgkDvS
Variables to adjust:
*** MySQL's maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
query_cache_size (=0)
query_cache_type (=0)
query_cache_limit (> 1M, or use smaller result sets)
performance_schema = ON enable PFS
innodb_log_file_size should be (=8M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.