SpringBoot集成Druid数据库连接池并配置可视化界面和监控慢SQL

pom.xml

xml 复制代码
        <!-- Druid 数据库连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.23</version>
        </dependency>

application.yml

yaml 复制代码
spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/spring_boot_demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
    username: root
    password: 123456
    druid:
      initial-size: 5
      min-idle: 1
      max-wait: 60000
      stat-view-servlet:
      	# 可视化页面
        enabled: true
        # 可视化界面用户名
        login-username: admin
        # 可视化界面密码
        login-password: admin
        # 可视化界面地址前缀
        url-pattern: "/druid/*"
      web-stat-filter:
        enabled: true
        url-pattern: "/*"
        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
      filter:
        stat:
          enabled: true
          # 数据库类型
          db-type: mysql
          # 记录慢SQL
          log-slow-sql: true
          # 默认慢SQL为500ms,这里改成2ms
          slow-sql-millis: 2

启动并执行一条SQL后打开监控页面

8080是你的SpringBoot项目端口

html 复制代码
http://localhost:8080/druid/index.html

执行一条SQL

打开SQL监控页面查看慢SQL

相关推荐
Decay__19 小时前
SQLServer 索引与 SQL 优化 —— 聚集索引、非聚集索引、覆盖索引、碎片维护与执行计划
运维·数据库·sql·mysql·架构
笃行35021 小时前
【金仓数据库产品体验官】订单增量同步实战:MERGE、OUTPUT 与 IDENTITY 的兼容验证
数据库
yuyuxun11 天前
协同过滤的校园二手物品智能推荐系统的设计与实现 毕业设计-附源码40082
javascript·vue.js·spring boot·python·数据分析·django·课程设计
星恒随风1 天前
MySQL 从零入门(六):复合查询详解——多表查询、自连接、子查询与 UNION
linux·服务器·数据库·mysql
无奈笑天下1 天前
银河麒麟上lsblk命令教程详解
linux·运维·服务器·数据库
LGL6030A1 天前
Java学习历程31——初识Spring Boot
java·spring boot·学习
xiaoye-duck1 天前
《C++ 项目:手写大模型接入 SDK》会话模块整合:内存 SessionManager 与 DataManager 持久化联动
开发语言·数据库·c++·语言模型
AllData公司负责人1 天前
AI大模型数据开发底座系列说明书:AllData集成DB-GPT开源项目建设 AI 多模态分析底座,涵盖模态解析/智能大屏/MCP 扩展!
大数据·数据库·人工智能·gpt·数据采集·数据接入·模态解析
2601_967987371 天前
Sqlite参考手册
数据库·python·sqlite·api·教程
阿达和自己1 天前
springboot学习-springboot引入MyBatis-Plus
spring boot·学习·mybatis