MySQL怎样记录所有执行过的SQL?
查看状态、日志所在目录
show variables LIKE '%general_log%' ;
variable_name | Value |
---|---|
general_log | OFF |
general_log_file | /Applications/xxx/Extensions/MySQL5.x.xx/data/yudemacbook-air.log |
开启
set global general_log=on;
set global general_log="on";
关闭
set global general_log=off;
set global general_log="off";
mysql 日志样本
Tcp port: 3306 Unix socket: /xxx/mysql.sock
Time Id Command Argument
2021-09-20T14:18:07.690019Z 168684 Query SHOW SESSION VARIABLES LIKE 'FOREIGN_KEY_CHECKS'
2021-09-20T14:18:07.757963Z 168685 Quit
2021-09-20T14:18:07.758061Z 168684 Quit
2021-09-20T14:18:16.994325Z 168686 Connect root@localhost on using Socket
2021-09-20T14:18:16.994470Z 168686 Query SELECT @@version, @@version_comment
2021-09-20T14:18:16.996132Z 168686 Query SET CHARACTER SET 'utf8mb4'
2021-09-20T14:18:16.996228Z 168686 Query SET collation_connection = 'utf8mb4_unicode_ci'
2021-09-20T14:18:16.996314Z 168686 Query SET lc_messages = 'zh_CN'
2021-09-20T14:18:16.996593Z 168687 Connect root@localhost on using Socket
2021-09-20T14:18:16.996701Z 168687 Query SET CHARACTER SET 'utf8mb4'
2021-09-20T14:18:16.996795Z 168687 Query SET collation_connection = 'utf8mb4_unicode_ci'
2021-09-20T14:18:16.996878Z 168687 Query SET lc_messages = 'zh_CN'
2021-09-20T14:18:17.006977Z 168686 Query SELECT `SCHEMA_NAME` FROM `INFORMATION_SCHEMA`.`SCHEMATA`
2021-09-20T14:18:17.024902Z 168686 Init DB mysql
2021-09-20T14:18:17.027017Z 168686 Query SHOW SESSION VARIABLES LIKE 'FOREIGN_KEY_CHECKS'
2021-09-20T14:18:17.038934Z 168686 Quit
其它问题
#1227 - Access denied; you need (at least one of) the SUPER privilege(s) for this operation
意思是拒绝访问;对于此操作您需要超级特权
解决方法是使用有root权限的账号操作。如果在宝塔上,则需要打开phpMyAdmi进入数据库操作
原创 转载请注明出处