Enabling MySQL general query log with JDBC(使用 JDBC 启用 MySQL 通用查询日志)
问题描述
有没有办法通过 JDBC 启用 MySQL 常规查询日志记录?我通过搜索发现的最接近的是能够通过 JDBC (http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html) 记录慢查询.也许我应该这样做并将慢查询阈值设置为 0 毫秒?
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 将二进制日志转换为人类可读的格式,但听起来通用查询日志将提供一种更简单的方法来获取我想要的内容.
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 通用查询日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 JDBC 启用 MySQL 通用查询日志


基础教程推荐
- SQL Server 2016更改对象所有者 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01