MySQL的全量日誌(general log)會記錄MySQL資料庫所有操作的SQL語句,包含select和show。預設情況下,禁用全量日誌。影片講解如下:
https://www.bilibili.com/video/BV1EaYkeZEKg/?aid=112954267798...
下面透過具體的步驟來演示如何使用全量日誌。
(1)檢視是否啟用全量日誌
mysql> show variables like '%general_log%';
# 輸出的資訊如下:
+------------------+-----------------------------------+
| Variable_name | Value |
+------------------+-----------------------------------+
| general_log | OFF |
| general_log_file | /usr/local/mysql/data/mysql11.log |
+------------------+-----------------------------------+
(2)臨時啟用全量日誌
mysql> set global general_log=ON;
(3)執行查詢
mysql> show databases;
mysql> use demo1;
mysql> select * from test2;
(4)檢視全量日誌
cat /usr/local/mysql/data/mysql11.log
# 輸出的資訊如下:
/usr/local/mysql/bin/mysqld, Version: 8.0.20 (MySQL Community Server - GPL).
started with:
Tcp port: 3306 Unix socket: /tmp/mysql.sock
Time Id Command Argument
2022-02-20T03:42:50.496566Z 8 Query show databases
2022-02-20T03:42:50.498045Z 8 Query SELECT DATABASE()
2022-02-20T03:42:50.498210Z 8 Init DB demo1
2022-02-20T03:42:51.576117Z 8 Query select * from test2