使用JDBC启用MySQL一般查询日志 [英] Enabling MySQL general query log with JDBC

查看:118
本文介绍了使用JDBC启用MySQL一般查询日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以通过JDBC启用MySQL一般查询日志记录?通过搜索发现的最接近的内容是能够通过JDBC(http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html)记录慢速查询的功能.也许我应该这样做并将慢查询阈值设置为0 ms?

Is there a way to enable MySQL general query logging through JDBC? The closest thing I have found through my search is the ability to log slow queries through JDBC (http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html). Maybe I should do that and set the slow query threshold to 0 ms?

我想通过MySQL以一种人类可读的格式记录所有查询,并希望指定应在其中写入日志文件的位置.我知道我会受到性能的影响,但是我的应用程序只有一个用户,而且非常简单,如果性能下降很明显,我会感到惊讶.无论如何,我想尝试一下.

I would like to log all queries through MySQL in a human-readable format and would like to specify the location where the log file should be written. I know I will take a performance hit, but my application only has one user and is simple enough that I would be surprised if the performance hit was noticeable. I would like to try it out anyway to see.

我相信我还有另一个选择是打开二进制日志记录,并使用mysqlbinlog将二进制日志转换为人类可读的格式,但这听起来像一般查询日志将提供一种获取我想要的内容的更简单方法. /p>

I believe another option I have is to turn on binary logging and use mysqlbinlog to convert the binary logs to a human-readable format, but it sounds like the general query log would provide a simpler means of getting what I want.

推荐答案

我最终找到了解决方法.通过在运行时使用以下SQL查询修改MySQL全局系统变量,可以通过Java启用MySQL常规查询日志记录.

I ended up finding a workaround. I enable MySQL general query logging through Java by modifying MySQL global system variables at runtime with the following SQL queries.

SET GLOBAL log_output="FILE"
SET GLOBAL general_log_file="Path/File"
SET GLOBAL general_log='ON'

我建议在general_log_file路径中使用正斜杠.即使在Windows环境中,我也无法使用反斜杠.

I recommend using forward slashes in the general_log_file path. I could not get backslashes to work, even in a Windows environment.

我在运行时使用以下SQL查询禁用常规查询日志记录.

I disable general query logging at runtime with the following SQL query.

SET GLOBAL general_log='OFF'

这篇关于使用JDBC启用MySQL一般查询日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆