MySQL的全量日志(general log)会记录MySQL数据库所有操作的SQL语句,包含select和show。默认情况下,禁用全量日志。视频讲解如下:
下面通过具体的步骤来演示如何使用全量日志。
(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