临时记录:
SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = 'C:/Users/admin/Desktop/log2/general_log.log';
永久记录
vim /etc/my.cnf
general_log = 1
general_log_file = /var/log/mysql/general_sql.log
# 然后重启mysqld
service mysqld restart
记录示例:
D:\laragon\bin\mysql\mysql-8.0.22-winx64\bin\mysqld.exe, Version: 8.0.22 (MySQL Community Server - GPL). started with:
TCP Port: 3306, Named Pipe: /tmp/mysql.sock
Time Id Command Argument
2021-07-09T02:22:27.650544Z 33 Connect dbxxx@localhost on dbxxx using TCP/IP
2021-07-09T02:22:27.652756Z 33 Query use `dbxxx`
2021-07-09T02:22:27.653478Z 33 Prepare set names 'utf8' collate 'utf8_general_ci'
2021-07-09T02:22:27.653851Z 33 Execute set names 'utf8' collate 'utf8_general_ci'
2021-07-09T02:22:27.654116Z 33 Close stmt
2021-07-09T02:22:27.654162Z 33 Prepare set session sql_mode='NO_ENGINE_SUBSTITUTION'
2021-07-09T02:22:27.654417Z 33 Execute set session sql_mode='NO_ENGINE_SUBSTITUTION'
2021-07-09T02:22:27.654692Z 33 Close stmt
2021-07-09T02:22:27.654860Z 33 Prepare select `name`, `value` from `admin_config`
2021-07-09T02:22:27.655443Z 33 Execute select `name`, `value` from `admin_config`
2021-07-09T02:22:27.655860Z 33 Close stmt
2021-07-09T02:22:27.673435Z 33 Prepare select * from `xxx_users` where `id` = ? limit 1
2021-07-09T02:22:27.674430Z 33 Prepare select * from `xxx_users` where `id` = ? limit 1
2021-07-09T02:22:27.674448Z 33 Execute select * from `xxx_users` where `id` = 5 limit 1
2021-07-09T02:22:27.675089Z 33 Close stmt
2021-07-09T02:22:27.774461Z 34 Connect yyyy@localhost on xxx using TCP/IP
2021-07-09T02:22:27.775474Z 34 Query use `xxx`
2021-07-09T02:22:27.776131Z 34 Prepare set names 'utf8' collate 'utf8_general_ci'
2021-07-09T02:22:27.776415Z 34 Execute set names 'utf8' collate 'utf8_general_ci'
2021-07-09T02:22:27.776691Z 34 Close stmt
2021-07-09T02:22:27.776737Z 34 Prepare set session sql_mode='NO_ENGINE_SUBSTITUTION'
2021-07-09T02:22:27.776983Z 34 Execute set session sql_mode='NO_ENGINE_SUBSTITUTION'
2021-07-09T02:22:27.777245Z 34 Close stmt
2021-07-09T02:22:27.777539Z 34 Prepare insert into `zzz` (`code`, `created_at`, `type`, `updated_at`) values (?, ?, ?, ?), (?, ?, ?, ?) on duplicate key update `type` = values(`type`), `updated_at` = values(`updated_at`)
2021-07-09T02:22:27.777959Z 34 Execute insert into `zzz` (`code`, `created_at`, `type`, `updated_at`) values ('CF2A9-15A16-Y483Z-52D7D', '1625797347', '123', '1625797347'), ('CF2A9-15A16-Y483Z-52D71', '1625797347', '122', '1625797347') on duplicate key update `type` = values(`type`), `updated_at` = values(`updated_at`)
2021-07-09T02:22:27.835230Z 34 Close stmt
2021-07-09T02:22:28.353735Z 33 Quit
2021-07-09T02:22:28.353755Z 34 Quit