MySQL如何开启记录从客户端收到的每条SQL查询语句和提交时间的功能? 我可以在phpmyadmin或NaviCat中这样做吗? 如何分析日志?
当前回答
我不得不在某一时刻放弃并重新创建一般日志。在重建过程中,字符集被弄乱了,我最终在日志中出现了以下错误:
mysql表定义错误。General_log:期望位置1的列'user_host'的类型有字符集'utf8',但发现字符集'latin1'
因此,如果“检查以确保日志记录开启”的标准答案对您不起作用,请检查以确保字段具有正确的字符集。
其他回答
MySQL 5.6版本有bug。 甚至mysqld显示为:
Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf c:\Program Files (x86)\MySQL\MySQL Server 5.6\my.ini c:\Program Files (x86)\MySQL\MySQL Server 5.6\my.cnf
实际设置按以下顺序读取:
Default options are read from the following files in the given order:
C:\ProgramData\MySQL\MySQL Server 5.6\my.ini C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf c:\Program Files (x86)\MySQL\MySQL Server 5.6\my.ini c:\Program Files (x86)\MySQL\MySQL Server 5.6\my.cnf
检查文件:C:\ProgramData\MySQL\MySQL Server 5.6\my.ini
希望它能帮助到一些人。
在phpMyAdmin 4.0,你去状态>监视器。在那里,您可以启用慢查询日志和常规日志,查看实时监视器,选择图表的一部分,查看相关查询并分析它们。
我还想让MySQL日志文件看到查询,我已经解决了这个问题与下面的说明
进入/etc/mysql/mysql.conf.d 打开mysqld.cnf . conf文件
并启用下面的行
general_log_file = /var/log/mysql/mysql.log
general_log = 1
使用/etc/init.重启MySQLd / mysql重启 进入/var/log/mysql/,检查日志
对于mysql>=5.5仅用于慢查询(1秒或更长时间) my.cfg
[mysqld]
slow-query-log = 1
slow-query-log-file = /var/log/mysql/mysql-slow.log
long_query_time = 1
log-queries-not-using-indexes
// To see global variable is enabled or not and location of query log
SHOW VARIABLES like 'general%';
// Set query log on
SET GLOBAL general_log = ON;