如何列印完整的MYSQL帶引數SQL日誌資訊

宇的季節發表於2020-08-04

在mysql的jdbc中開啟sql分析,如下:

jdbc.url=jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&logger=com.mysql.jdbc.log.Slf4JLogger&profileSQL=true

如此便可以生成完整的SQL資訊

[2020-08-04 20:27:05,273] INFO com.mysql.jdbc.log.Slf4JLogger.logInfo(Slf4JLogger.java:88) - FETCH created: Tue Aug 04 20:27:05 CST 2020 duration: 1 connection: 587 statement: 129 resultset: 156
[2020-08-04 20:27:05,274] INFO com.mysql.jdbc.log.Slf4JLogger.logInfo(Slf4JLogger.java:88) - QUERY created: Tue Aug 04 20:27:05 CST 2020 duration: 1 connection: 587 statement: 128 resultset: 0 message: update item_costs set num_iid=7777777772 where id=18
[2020-08-04 20:27:05,275] INFO com.mysql.jdbc.log.Slf4JLogger.logInfo(Slf4JLogger.java:88) - FETCH created: Tue Aug 04 20:27:05 CST 2020 duration: 0 connection: 587 statement: 128 resultset: 0
[2020-08-04 20:27:05,278] INFO com.mysql.jdbc.log.Slf4JLogger.logInfo(Slf4JLogger.java:88) - QUERY created: Tue Aug 04 20:27:05 CST 2020 duration: 0 connection: 587 statement: 131 resultset: 157 message: select @@session.tx_read_only
[2020-08-04 20:27:05,279] INFO com.mysql.jdbc.log.Slf4JLogger.logInfo(Slf4JLogger.java:88) - FETCH created: Tue Aug 04 20:27:05 CST 2020 duration: 1 connection: 587 statement: 131 resultset: 157
[2020-08-04 20:27:05,280] INFO com.mysql.jdbc.log.Slf4JLogger.logInfo(Slf4JLogger.java:88) - QUERY created: Tue Aug 04 20:27:05 CST 2020 duration: 0 connection: 587 statement: 130 resultset: 0 message: update skus set num_iid=7777777772 where id=19
[2

 

https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html

相關文章