天天看點

檢視MySQL最近執行的語句

首先登入MySQL。

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2294
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [xxx]> 
      

  

先檢視一下二進制的記錄日志是否打開。

MariaDB [xxx]> show variables where Variable_name="general_log";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| general_log   | ON    |
+---------------+-------+
1 row in set (0.01 sec)
      

我這裡看起來是打開的,如果是

OFF

。則需要打開這個選項:

set global general_log=on;
      

然後确認一下預設的log産生在哪裡:

MariaDB [xxx]> show variables where Variable_name="general_log_file";
+------------------+-----------------+
| Variable_name    | Value           |
+------------------+-----------------+
| general_log_file | 10-0-236-38.log|
+------------------+-----------------+
1 row in set (0.00 sec)
      

然後搜尋一下它,得到日志路徑:

[root@10-0-236-38 ~]# find / -name "10-0-236-38.log"
/var/lib/mysql/10-0-236-38.log
      

大功告成。

[root@10-0-236-38 ~]# vim /var/lib/mysql/10-0-236-38.log 
      

繼續閱讀