Home > Database > Mysql Tutorial > How Can I Monitor Real-Time MySQL Queries on a Linux Server?

How Can I Monitor Real-Time MySQL Queries on a Linux Server?

Susan Sarandon
Release: 2024-12-04 21:34:12
Original
604 people have browsed it

How Can I Monitor Real-Time MySQL Queries on a Linux Server?

Real-Time MySQL Query Monitoring on Linux

Monitoring MySQL queries in real-time is essential for optimizing database performance and troubleshooting issues. This article will guide you through a simple and effective method to trace live queries on your Linux server.

Logging MySQL Queries

To capture every query executed by the MySQL server, you can enable general logging. Run the following commands:

mysql> SHOW VARIABLES LIKE "general_log%";

mysql> SET GLOBAL general_log = 'ON';
Copy after login

Examine Query Log

Once general logging is enabled, perform your database operations. The queries will be logged in the file /var/run/mysqld/mysqld.log. You can use a command like grep to examine the log and filter specific queries.

grep "SELECT *" /var/run/mysqld/mysqld.log
Copy after login

Disable General Logging

Remember to disable general logging once you have gathered the necessary data:

mysql> SET GLOBAL general_log = 'OFF';
Copy after login

By following these steps, you can easily monitor live MySQL queries on your Linux server and gain insights into database performance and behavior.

The above is the detailed content of How Can I Monitor Real-Time MySQL Queries on a Linux Server?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template