简体   繁体   English

MySQL常规日志缺少时间戳

[英]MySQL General Log missing Timestamps

I want to determine when an event occurred in the General Query Log of MySQL (v5.1.71). 我想确定MySQL(v5.1.71)的通用查询日志中何时发生了事件。 As an example, on the server OS CLI (Unix), I ran a simple grep to pull out data from the log file: 例如,在服务器OS CLI(Unix)上,我运行了一个简单的grep来从日志文件中提取数据:

grep "Access denied" /data/mysql/my_servername.log grep“访问被拒绝” /data/mysql/my_servername.log

            1249390 Connect Access denied for user 'user1'@'user.1.ip.add' (using password: YES)
131204 17:51:00 1254417 Connect Access denied for user 'user2'@'user.2.ip.add' (using password: NO)

I looked at the entire log for other types of information I would be pulling out, and noticed entries were missing timestamps as well. 我在整个日志中查找了我将要提取的其他类型的信息,并且注意到条目也缺少时间戳。 It appears MySQL only precedes the log entry with YYMMDD HH:MI:SS when the SS value has changed since the last log entry. 自从上一个日志条目以来更改了SS值后,MySQL似乎仅在日志条目之前带有YYMMDD HH:MI:SS。 In the above example, I would have no way of determing the DATE/TIME of user1's log entry, since I would only have the milli/nano/whatever second. 在上面的示例中,我无法确定user1的日志条目的日期/时间,因为我只有毫秒/纳米/秒。

I'm currently running mysql with the following options: --user=mysql --general_log --ssl-ca=/path_to_file1 --ssl-cert=/path_to_file2 --ssl-key=/path_to_file3 我当前正在使用以下选项运行mysql:--user = mysql --general_log --ssl-ca = / path_to_file1 --ssl-cert = / path_to_file2 --ssl-key = / path_to_file3

So how do get MySQL to put a timestamp on every line? 那么,如何使MySQL在每一行上添加时间戳?

SK SK

You should use pt-query-digest for this. 您应该为此使用pt-query-digest

Start with something like this: 首先是这样的:

pt-query-digest \
--type genlog \
--print \
--no-report \
--filter '$event->{arg} && $event->{arg} =~ /Access denied/' \
/data/mysql/my_servername.log

Alternatively, you can switch the log format from FILE to TABLE (do this in your my.cnf file too so it survives a restart), and the timestamp will be present for each row in the table: 或者,您可以将日志格式从FILE切换为TABLE (也可以在my.cnf文件中执行此操作,以便它在重新启动后仍然存在),并且表中的每一行都会显示时间戳记:

set global log_output='TABLE';

Now you can query the table instead of grepping the file: 现在,您可以查询表而不是对文件进行grep处理:

select * from mysql.general_log where argument like 'Access denied%';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM