Many developers encounter the need to monitor live MySQL queries to troubleshoot performance issues or debug code. This article provides several methods for tracing MySQL queries as they occur.
One simple method is to enable general logging, which records all queries to a log file. To do this:
mysql> SHOW VARIABLES LIKE "general_log%"; +------------------+----------------------------+ | Variable_name | Value | +------------------+----------------------------+ | general_log | OFF | | general_log_file | /var/run/mysqld/mysqld.log | +------------------+----------------------------+ mysql> SET GLOBAL general_log = 'ON';
After executing the queries, examine the log file (/var/run/mysqld/mysqld.log) to view the executed queries. Remember to disable logging after troubleshooting to prevent performance and storage issues:
mysql> SET GLOBAL general_log = 'OFF';
The above is the detailed content of How Can I Debug MySQL Queries in Real Time?. For more information, please follow other related articles on the PHP Chinese website!