MySQL如何开启记录从客户端收到的每条SQL查询语句和提交时间的功能? 我可以在phpmyadmin或NaviCat中这样做吗? 如何分析日志?
当前回答
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
希望它能帮助到一些人。
其他回答
首先,请记住,这个日志文件在繁忙的服务器上可能会变得非常大。
对于mysql < 5.1.29:
要启用查询日志,请将其放在/etc/my.cnf的[mysqld]部分
log = /path/to/query.log #works for mysql < 5.1.29
另外,从MySQL控制台启用它
SET general_log = 1;
参见http://dev.mysql.com/doc/refman/5.1/en/query-log.html
mysql 5.1.29+
在mysql 5.1.29+中,日志选项已弃用。要指定日志文件并启用日志记录,请在my.cnf的[mysqld]部分中使用这个:
general_log_file = /path/to/query.log
general_log = 1
另外,要从MySQL控制台打开日志记录(还必须以某种方式指定日志文件位置,或者找到默认位置):
SET global general_log = 1;
还要注意,还有其他选项可以只记录慢速查询或不使用索引的查询。
我不得不在某一时刻放弃并重新创建一般日志。在重建过程中,字符集被弄乱了,我最终在日志中出现了以下错误:
mysql表定义错误。General_log:期望位置1的列'user_host'的类型有字符集'utf8',但发现字符集'latin1'
因此,如果“检查以确保日志记录开启”的标准答案对您不起作用,请检查以确保字段具有正确的字符集。
可以禁用或启用常规查询日志(记录所有查询)
SET GLOBAL general_log = 1 # (or 0 to disable)
// 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;
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
希望它能帮助到一些人。
推荐文章
- 在MySQL中检测值是否为number
- MySQL中两个日期之间的差异
- 为什么在MySQL中文本列不能有一个默认值?
- 使用SQL查询查找最近的纬度/经度
- 有nginx access_log和error_log日志的STDOUT和STDERR的主进程
- 如何停止mysqld
- 检查MySQL表是否存在而不使用“select from”语法?
- 从NOW() -1天选择记录
- 从表中选择1是什么意思?
- 在Python Django中运行单元测试时,如何禁用日志记录?
- 数据库性能调优有哪些资源?
- 如何更改表的默认排序规则?
- MySQL foreign_key_checks是否影响整个数据库?
- 哪里是logging.config.dictConfig的完整示例?
- 设置NOW()为datetime数据类型的默认值?