Monitoring MySQL server health and performance metrics
Jul 03, 2025 am 02:31 AMMonitoring MySQL health and performance requires five core dimensions. 1. Check the number of connections and thread status, and use SHOW STATUS LIKE 'Threads%'; Check Threads_connected and Threads_running. If Threads_running is higher than 10~20 for a long time, you need to combine the slow query log troubleshooting; 2. Enable and analyze the slow query log, configure slow_query_log, long_query_time, use mysqldumpslow or pt-query-digest analysis to optimize the SQL of the missed index; 3. Monitor the InnoDB status, pay attention to the buffer pool hit rate, log sequence number and checkpoint gap, and row operation status, and reasonably set innodb_buffer_pool_size; 4. Use system tools such as top, iostat, and vmstat and Prometheus Grafana collects CPU, IO, memory and other indicators, pay attention to the disk queue length and swap usage; 5. Adjust the configuration according to the data volume to avoid frequent restarts causing the buffer pool to be coldly started, and ensure reasonable resource allocation.
The key to monitoring the health and performance metrics of MySQL servers is to master several core dimensions. You don't need to go deep into the source code every time, but you must be able to quickly judge whether the system is normal and whether there are potential bottlenecks through some common indicators.

Check the number of connections and thread status
The number of connections and thread state of MySQL are the first window that reflects the service load. If the number of connections continues to grow or even approaches the maximum limit, it may be that there may be slow queries or the client does not release the connection correctly.

-
Threads_connected
: The number of currently open connections -
Threads_running
: The number of threads that are executing tasks. Too high may be due to a large number of concurrent operations or slow query
You can use the following command to view:
SHOW STATUS LIKE 'Threads%';
suggestion:

- Set the appropriate maximum number of connections (
max_connections
), do not set too high to cause resource exhaustion, and do not affect business too low. - If you find
Threads_running
is greater than 10~20 for a long time, you can troubleshoot problems with the slow query log.
Pay attention to slow query logs and query efficiency
Slow queries are one of the main reasons for slowing down database performance. Turn on slow query logs and analyze them regularly to help you find out those statements that "stuck" the database.
Enable method (in configuration file):
slow_query_log = 1 long_query_time = 1 log_slow_queries = /var/log/mysql/mysql-slow.log
suggestion:
- Regularly use
mysqldumpslow
or third-party tools (such as pt-query-digest) to analyze slow query logs - Add index or optimize structure for frequent execution and time-consuming SQL
- Use
EXPLAIN
to analyze the execution plan and confirm whether the index is hit
Monitor InnoDB status and buffer pool usage
If you are using the InnoDB engine, its status information is very important. In particular, the usage rate of buffer pools is directly related to read and write performance.
Commonly used commands:
SHOW ENGINE INNODB STATUS\G
Focus:
- Buffer pool hit rate : cache hit rate, below 95% may require increasing buffer pool size (
innodb_buffer_pool_size
) - Log sequence number and Last checkpoint at : The gap is too large, which means that the write pressure is large, check the disk IO capability
- Read/delete/update in Row operations , assist in judging load type
suggestion:
- Set a reasonable buffer pool size according to the data volume, usually set to 50%~80% of physical memory
- Do not restart MySQL frequently to avoid performance fluctuations caused by cold start of buffer pools
Collect real-time metrics using system monitoring tools
In addition to the state inside the database, data at the operating system level is also very important. For example, CPU usage, IO latency, memory usage, etc. will affect MySQL performance.
Recommended tools:
-
top
,htop
: Look at the overall CPU usage -
iostat
: Check whether disk IO becomes a bottleneck -
vmstat
: Understand memory and swap usage - Prometheus Grafana: Visualize long-term trends, suitable for production environments
Tips:
- In high concurrency scenarios, the CPU is often not a bottleneck, but IO is the one. Remember to pay attention to disk queue length (
%util
andawait
iniostat -x
) - If insufficient memory leads to frequent use of swap, MySQL performance will drop sharply. In this case, it should be expanded or optimized in time
Basically that's it. MySQL monitoring is not complicated, but details are easily overlooked. If you focus on the above aspects, most performance problems can be discovered in time.
The above is the detailed content of Monitoring MySQL server health and performance metrics. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Performance indicators of "graphics card". CGA (Color Graphics Adapter) is the computer display standard on the first IBM PC; VGA (Video Graphics Array) is a computer display standard using analog signals; EGA (Enhanced Graphics Adapter) is the IBM PC computer display standard definition, with performance between between CGA and VGA.

Computer performance indicators include: 1. Computer speed; 2. Word length; 3. Storage cycle; 4. Storage capacity. A computer is a modern electronic computing machine used for high-speed calculations. It can perform numerical calculations and logical calculations, and also has a storage and memory function.

How to use performance monitoring tools in Java to monitor system performance indicators in real time? Overview: As computer technology develops and the complexity of computer systems increases, monitoring system performance becomes increasingly important. Performance monitoring can help us understand the health of the system and provide a basis for improving system performance. Java provides a variety of performance monitoring tools. This article will introduce how to use performance monitoring tools in Java to monitor system performance indicators in real time. JMX(JavaManagementExtensio

How to handle key performance indicators and performance testing in C# development requires specific code examples. In C# development, performance is a very important consideration. When we develop a project, whether it's a desktop application, web application, or mobile application, we want it to run fast enough without lags or delays during use. Therefore, we need to pay attention to and deal with key performance indicators and conduct performance testing to ensure the high performance and stability of the application. Handling Key Performance Indicators Handling Key Performance Indicators

The performance indicators of the hard disk include capacity, speed, rotation speed, cache, response time, interface type, and reliability. Detailed introduction: 1. Capacity, the capacity of a hard disk refers to the amount of data it can store, usually in bytes; 2. Speed, the speed indicators of the hard disk include reading speed and writing speed, and the reading speed refers to the data transferred from the hard disk. The speed of reading data, and the writing speed refers to the speed at which data is written to the hard disk; 3. Rotation speed, the rotation speed of the hard disk refers to the speed at which the hard disk platters rotate, usually expressed in revolutions per minute (RPM); 4. Caching, etc.

The MySQL database plays a very important role in modern web application development. Therefore, monitoring and fault warning of the MySQL database is one of the skills that every developer should master. In this article, I will share my experience summary in a MySQL database monitoring and fault warning project. Before starting the project, we first need to determine the goals of monitoring and fault warning. We hope to be able to monitor the performance indicators, capacity utilization, number of connections, slow queries and other information of the database, and to be able to send out information in a timely manner.

To monitor the health and performance of MySQL servers, you should pay attention to system health, performance metrics and query execution. 1) Monitor system health: Use top, htop or SHOWGLOBALSTATUS commands to view CPU, memory, disk I/O and network activities. 2) Track performance indicators: monitor key indicators such as query number per second, average query time and cache hit rate. 3) Ensure query execution optimization: Enable slow query logs, record and optimize queries whose execution time exceeds the set threshold.

With the advent of the big data era, MySQL database, as an efficient data storage and management tool, has been widely used in various enterprises and organizations. However, due to data security and performance issues, MySQL's monitoring and alerting system has become increasingly important. The role of the MySQL monitoring and alarm system The MySQL monitoring and alarm system can detect the running status of the MySQL server in real time, including CPU load, memory usage, network traffic, disk space, index usage, number of queries, etc.
