How to Monitor MySQL Performance in Real-Time with mysqlstat
The mysqlstat command‑line tool provides real‑time monitoring and analysis of MySQL servers, offering metrics such as QPS, TPS, network bandwidth, top‑executed SQL statements, hot tables, lock and deadlock information, index analysis, connection counts, table size statistics, binlog insights, and replication status, with usage examples and download instructions.
Overview
mysqlstat is an open‑source command‑line utility for real‑time monitoring and analysis of MySQL 5.7/8.0 servers. It connects to a MySQL instance using the supplied host, port, user and password, then queries performance_schema, information_schema and SHOW ENGINE INNODB STATUS to collect metrics.
Key Features
Live monitoring of QPS (queries per second), TPS (transactions per second) and network bandwidth.
Top‑N SQL statements by execution count.
Top‑N accessed .ibd table files.
Current lock‑blocking SQL and deadlock information.
Detection of duplicate or redundant indexes.
Connection count per client IP.
Per‑table size statistics.
Binlog analysis to identify high‑traffic tables.
Master‑slave replication status and lag.
Architecture
Usage
After making the binary executable, run the tool with the desired options. If no options are supplied, the default view shows live QPS, TPS and bandwidth.
chmod 755 mysqlstat
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang'Common command‑line options:
options:
-h, --help show this help message and exit
-H MYSQL_IP, --mysql_ip MYSQL_IP MySQL IP address
-P MYSQL_PORT, --mysql_port MYSQL_PORT MySQL port
-u MYSQL_USER, --mysql_user MYSQL_USER MySQL user name
-p MYSQL_PASSWORD, --mysql_password MYSQL_PASSWORD MySQL password
--top N Show top N SQL statements by execution count
--io N Show top N .ibd files by access count
--lock Show currently lock‑blocked SQL statements
--dead Show deadlock information
--index Show duplicate/redundant indexes
--conn Show total connection count per client IP
--tinfo Show size of each table in the database
--binlog Analyze binlog to find tables with high TPS
--repl Show master‑slave replication status
-v, --version show program's version number and exitExample commands:
Top 10 SQL statements:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --top 10Top 10 accessed tables:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --io 10Show lock‑blocking SQL:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --lockShow duplicate indexes:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --indexShow connection counts per IP:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --connShow per‑table size information:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --tinfoShow deadlock information:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --deadBinlog analysis (default range):
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --binlogShow replication status:
./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --replCompatibility and Setup
The tool runs on CentOS 7 and supports MySQL 5.7 and 8.0. MySQL 8.0 uses the caching_sha2_password authentication plugin by default; if authentication fails, switch to mysql_native_password:
CREATE USER 'rd'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
GRANT ALL ON *.* TO 'rd'@'%';Download
Source code and binary releases are available at the following GitHub repository:
https://github.com/hcymysql/mysqlstat
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
dbaplus Community
Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
