Enable MySQL general query log using JDBC

Is there any way to enable MySQL general query records through JDBC? The closest thing I found through my search was the ability to record slow queries through JDBC( http://dev.MysqL.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html )Maybe I should do this and set the slow query threshold to 0 ms?

I want to record all queries in human readable format through MySQL and want to specify the location where the log file should be written I know I'll do a show, but my application has only one user, and it's very simple. I'll be surprised if performance is valued I want to try, anyway

I believe another option is to turn on binary logging and use mysqlbinlog to convert binary logging to a human readable format, but it sounds like a general query log will provide a simpler way to get what I want

Solution

You can enable logging in JDBC URLs as follows:

jdbc:MysqL://host/db?logger=com.MysqL.jdbc.log.Log4JLogger&profilesql=true

Other logs are available in the background (commonslogger, slf4jlogger, jdk14logger) I believe the log4j log record was deleted at some point due to a licensing problem, so it may not work with your jdbc driver version

Of course, you need to use the jar of the relevant logging library and the configuration file (log4j. Properties) in the classpath Once you see what is being recorded, I will first set the root level to trace to see what happened and tighten the log level and category

Further reading:

> https://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html > http://docs.oracle.com/cd/E17952_01/mysql-monitor-2.3-en/mem-qanal-using-cj.html

HTH

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>