Databases 8 min read

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.

dbaplus Community
dbaplus Community
dbaplus Community
How to Monitor MySQL Performance in Real-Time with mysqlstat

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

mysqlstat architecture diagram
mysqlstat architecture diagram

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 exit

Example commands:

Top 10 SQL statements:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --top 10

Top 10 accessed tables:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --io 10

Show lock‑blocking SQL:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --lock

Show duplicate indexes:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --index

Show connection counts per IP:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --conn

Show per‑table size information:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --tinfo

Show deadlock information:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --dead

Binlog analysis (default range):

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --binlog

Show replication status:

./mysqlstat -H 192.168.198.239 -P 6666 -u admin -p 'hechunyang' --repl

Compatibility 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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Performance Monitoringmysqlopen sourcecommand-lineDatabase Administration
dbaplus Community
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.