执行SQL分析打印

p6spy

mybatis-plus执行sql打印。

1 p6spy

1.1 引入pom

xml 复制代码
<!-- https://mvnrepository.com/artifact/p6spy/p6spy -->
<dependency>
    <groupId>p6spy</groupId>
    <artifactId>p6spy</artifactId>
    <version>3.9.1</version>
</dependency>

1.2 配置文件 spy.properties

bash 复制代码
#3.2.1以上使用
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
# 自定义日志打印
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
#日志输出到控制台
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
# 使用日志系统记录 sql
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
# 设置 p6spy driver 代理
deregisterdrivers=true
# 取消JDBC URL前缀
useprefix=true
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
excludecategories=info,debug,result,commit,resultset
# 日期格式
dateformat=yyyy-MM-dd HH:mm:ss
# 实际驱动可多个
driverlist=com.mysql.cj.jdbc.Driver
# 是否开启慢SQL记录
outagedetection=true
# 慢SQL记录标准 2 秒
outagedetectioninterval=2

1.3 驱动连接

bash 复制代码
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
url 前缀为 jdbc:p6spy 跟着冒号为对应数据库连接地址

2 p6spy-spring-boot-starter

2.1 pom

xml 复制代码
<dependency>
    <groupId>com.github.gavlyukovskiy</groupId>
    <artifactId>p6spy-spring-boot-starter</artifactId>
    <version>1.8.1</version>
</dependency>

1.9.0以及以上版本使用的是spring boot3.0+,

2.2 配置

yml 复制代码
#  版本高于1.8.1无法打印出来(使用的是springboot2+)|1.9版本使用的好像是springboot3.0
decorator:
  datasource:
    p6spy:
      logging: slf4j
      # 全部可用参数参照该类:com.p6spy.engine.spy.appender.CustomLineFormat
      log-format: "\ntime:%(executionTime) || sql:%(sqlSingleLine)"
    # 是否启动
    enabled: true

spy.properties 和 decorator 配置同时存在

如果decorator配置和spy.properties 配置同时存在,起作用的是 spy.properties配置

druid

#配置扩展插件|druid和p6spy 有冲突,去掉了wall

#spring.datasource.druid.filters=stat,slf4j

相关推荐
我是一颗柠檬3 小时前
【MySQL全面教学】MySQL基础SQL语句Day3(2026年)
数据库·后端·sql·mysql·oracle
XS0301064 小时前
MyBatis动态SQL
数据库·sql·mybatis
hef2887 小时前
SQL和Python怎么选?数据分析工具实战指南
python·sql·数据分析
顾凌陵8 小时前
SQL注入漏洞进阶篇
网络·sql
ZengLiangYi9 小时前
ChatCrystal大量对话导入时的内存优化
sql·ai编程
Full Stack Developme10 小时前
SQL like 与 正则 区别
数据库·sql·mysql
我是一颗柠檬10 小时前
【MySQL全面教学】MySQL多表查询与JOIN Day6(2026年)
数据库·后端·sql·mysql
网管NO.11 天前
SQL 日期函数全套精讲!时间格式化、日期加减、年月日提取,做日报周报直接套用
数据库·sql
一拳一个娘娘腔1 天前
【SRC漏洞挖掘系列】第03期:SQL注入——从“拖库”到“掌舵”的终极奥义
数据库·sql·安全
青春万岁!!1 天前
hiveSQL脚本性能优化-减少表扫描
大数据·hive·sql