Home > Database > Mysql Tutorial > How Can I Debug MySQL Queries in Real Time?

How Can I Debug MySQL Queries in Real Time?

Mary-Kate Olsen
Release: 2024-12-04 16:39:13
Original
576 people have browsed it

How Can I Debug MySQL Queries in Real Time?

Debugging MySQL Queries in Real Time

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.

Logging Queries

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';
Copy after login

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';
Copy after login

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!

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