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';
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
Disable General Logging
Remember to disable general logging once you have gathered the necessary data:
mysql> SET GLOBAL general_log = 'OFF';
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!