This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15074|Reply: 0

[Source] MySQL views SQL statements that are executed in real time

[Copy link]
Posted on 11/15/2017 1:26:51 PM | | | |

By default, MySQL cannot view executed SQL statements in real time, as this consumes a certain amount of resources.

To enable this function, configure it a little and open this LOG record.



1 View the LOG function
First, check whether real-time SQL statement recording is enabled.

mysql> SHOW VARIABLES LIKE "general_log%";
The following general_log value is OFF to indicate that it is not turned on:


2 Turn on the LOG function

2.1 Temporarily open

As follows, enable the real-time recording of SQL statements feature and specify a custom log path:


These two commands expire after MySQL is restarted and are temporary methods.

Note: This file will continue to grow larger as accesses increase, so it is recommended to open it temporarily in the production environment and close it when it runs out.

2.2 Permanently on
To make it permanently valid, you need to configure the my.cnf file and add the following two lines:


Restarting MySQL takes effect.

3 Real-time viewing
After a short period of time, you can export and view the /var/lib/mysql/sql_statement.log file, which records all executed SQL statements.

If you want to see the changes to the file in real time, use the tail command on Linux:

$ tail -f /var/lib/mysql/general_sql.log
Alternatively, it can be viewed in real time with BareTail software.




Previous:Teach you how to use Myisamchk for crash recovery MySQL
Next:Check whether the mysql table is corrupted, repaired, or optimized
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com