千家信息网

mysql开启general_log记录sql执行记录

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,方法一:更改my.cnf配置文件vi /usr/local/kkmail/config/mysql/my.cnf将下面两行注释取消掉,然后重启mysql#general_log = 1#general
千家信息网最后更新 2025年01月20日mysql开启general_log记录sql执行记录

方法一:更改my.cnf配置文件

vi /usr/local/kkmail/config/mysql/my.cnf将下面两行注释取消掉,然后重启mysql#general_log = 1#general_log_file = /tmp/kkmail_mysql.log

# 设置general log保存路径
# 好像只能设置保存到 /tmp 或 /var 文件夹下。



方法二:在mysql命令控制台操作

# 需要root用户才有访问此文件的权限mysql> show global variables like '%general%';+------------------+----------------------------------------------------+| Variable_name    | Value                                              |+------------------+----------------------------------------------------+| general_log      | OFF                                                || general_log_file | /usr/local/kkmail/data/mysql/default/localhost.log |+------------------+----------------------------------------------------+2 rows in set (0.00 sec)mysql> set global general_log_file='/tmp/kkmail_mysql.log';Query OK, 0 rows affected (0.00 sec)mysql> set global general_log=on;Query OK, 0 rows affected (0.05 sec)mysql> show global variables like '%general%';+------------------+----------------------+| Variable_name    | Value                |+------------------+----------------------+| general_log      | ON                   || general_log_file | /tmp/kkmail_mysql.log |+------------------+----------------------+2 rows in set (0.00 sec)mysql> set global general_log=off;Query OK, 0 rows affected (0.00 sec)mysql> show global variables like '%general%';+------------------+----------------------+| Variable_name    | Value                |+------------------+----------------------+| general_log      | OFF                  || general_log_file | /tmp/kkmail_mysql.log |+------------------+----------------------+2 rows in set (0.00 sec)



方法三:将日志保存在mysql数据库general_log表中

mysql> set global log_output='table';Query OK, 0 rows affected (0.00 sec)mysql> show global variables like '%general%';+------------------+----------------------+| Variable_name    | Value                |+------------------+----------------------+| general_log      | OFF                  || general_log_file | /tmp/kkmail_mysql.log |+------------------+----------------------+2 rows in set (0.00 sec)mysql> set global general_log=on;Query OK, 0 rows affected (0.00 sec)mysql> show global variables like '%general%';+------------------+----------------------+| Variable_name    | Value                |+------------------+----------------------+| general_log      | ON                   || general_log_file | /tmp/kkmail_mysql.log |+------------------+----------------------+2 rows in set (0.01 sec)mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> select * from general_log;


0