Mybatis-Plus使用p6spy對SQL性能進行監(jiān)控的方法
第一步、引入maven依賴
<!-- p6spy sql性能分析工具--> <dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>3.9.1</version> </dependency>
第二步、修改yml配置
原先的url
和driver-class-name
修改成p6spy
的驅(qū)動和url
形式。
本質(zhì)上p6spy相當(dāng)于代理了jdbc操作
server: port: 8088 spring: datasource: driver-class-name: com.p6spy.engine.spy.P6SpyDriver url: jdbc:p6spy:mysql://localhost:3306/mp_high?useSSL=false&serverTimezone=GMT%2B8 # driver-class-name: com.mysql.cj.jdbc.Driver # url: jdbc:mysql://localhost:3306/mp_high?useSSL=false&serverTimezone=GMT%2B8 username: root password: 123456 mybatis-plus: configuration: map-underscore-to-camel-case: true # 開啟駝峰命名
第三步、新建一個spy.properties文件
spy.properties
文件內(nèi)容:填入jdbc連接的驅(qū)動,以及日志輸出配置
driverlist=com.mysql.cj.jdbc.Driver logMessageFormat=com.p6spy.engine.spy.appender.MultiLineFormat #logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat databaseDialectDateFormat=yyyy-MM-dd HH:mm:ss appender=com.p6spy.engine.spy.appender.StdoutLogger
完成!然后就可以在控制臺中查看到執(zhí)行sql返回數(shù)據(jù)消耗的時間例如:
@Autowired UserMapper userMapper; @Test public void selectTest(){ List<User> users = userMapper.selectList(null); System.out.println(users); }
然后就可以根據(jù)sql的執(zhí)行效率分析sql對sql進行優(yōu)化,當(dāng)然建議并發(fā)執(zhí)行取平均值作為參考數(shù)據(jù)
到此這篇關(guān)于Mybatis-Plus使用p6spy對SQL性能進行監(jiān)控的方法的文章就介紹到這了,更多相關(guān)Mybatis-Plus SQL性能監(jiān)控內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java之不通過構(gòu)造函數(shù)創(chuàng)建一個對象問題
這篇文章主要介紹了Java之不通過構(gòu)造函數(shù)創(chuàng)建一個對象問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03springBoot的事件機制GenericApplicationListener用法解析
這篇文章主要介紹了springBoot的事件機制GenericApplicationListener用法解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值的相關(guān)資料2019-09-09在CentOS系統(tǒng)上安裝Java的openjdk的方法
這篇文章主要介紹了在CentOS系統(tǒng)上安裝Java的openjdk的方法,同樣適用于Fedora等其他RedHat系的Linux系統(tǒng),需要的朋友可以參考下2015-06-06