How to view the statements executed by the mysql database in real time

The parameter general_log in MySQL is used to control the opening and closing of the MySQL query log, and the parameter general_log_file is used to control the location of the query log. So if you want to determine whether the query log is enabled in the MySQL database, you can use the following command. If general_log is ON, the query log is turned on, and OFF is the query log is turned off.

mysql> show variables like '%general_log%';
+------------------+-----------------------------------------------------------------+
| Variable_name    | Value
     |
+------------------+-----------------------------------------------------------------+
| general_log      | OFF
     |
| general_log_file | D:\phpstudy_pro\Extensions\MySQL5.7.26\data\LS--20200725FKO.log |
+------------------+-----------------------------------------------------------------+
2 rows in set, 1 warning (0.05 sec)

Enable MySQL query log

mysql> set global general_log = on;
Query OK, 0 rows affected (0.06 sec)

Set the log output mode to table

查看
mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output    | FILE  |
+---------------+-------+
1 row in set, 1 warning (0.00 sec)
设置
mysql> set global log_output='table';
Query OK, 0 rows affected (0.00 sec)

When you see the following appears, it means success.

mysql> select * from mysql.general_log;
+----------------------------+------------------------------------+-----------+-----------+--------------+----------------------------------+
| event_time| user_host| thread_id |server_id | command_type |argument|
+----------------------------+------------------------------------+-----------+-----------+--------------+----------------------------------+
| 2020-07-30 09:06:42.805068 | root[root] @ localhost[127.0.0.1]|132 |1 | Query| show variables like 'log_output' | 
| 2020-07-30 09:06:46.517875 | root[root] @ localhost [127.0.0.1] |132 |1 | Query| select * from mysql.general_log  |
+----------------------------+------------------------------------+-----------+-----------+--------------+----------------------------------+
2 rows in set (0.00 sec)

Then we use BareTail to connect to the log to check it is more convenient. If you need this software, you can add me qq: 3075999532 (you can also Baidu by yourself).
Insert picture description here
The MySQL query log can basically locate the SQL that has performance problems, so there are not many scenarios for the MySQL query log application, which is a bit tasteless.
Reference: https://www.cnblogs.com/frankltf/p/8723944.html

Guess you like

Origin blog.csdn.net/p_utao/article/details/107681607