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

相关推荐
A.说学逗唱的Coke6 小时前
【大模型专题】向量数据库深度解析:从原理到实战,构建企业级 AI 知识检索底座
数据库·人工智能
果丁智能6 小时前
智能锁赋能网约房民宿数字化管控:身份核验+远程授权,筑牢安全防线、降本增效
网络·数据库·人工智能·安全·智能家居
无敌的牛6 小时前
redis学习过程
数据库·redis·学习
IT北辰6 小时前
神通数据库管理系统V7.0.251210 for Windows(x86 64bit)安装部署
数据库·神通
北顾笙9807 小时前
MySQL-day2
数据库·mysql
Demons_kirit7 小时前
新项目如何连接上自己本地的数据库
数据库
洪晓露8 小时前
将 rke2 集群证书延长至 10 年
运维·服务器·数据库
程序猿乐锅8 小时前
【MySQL | 第八篇】MySQL 视图
数据库·mysql
jieyucx9 小时前
SQL 查询终极高阶通鉴:从零基础拆解到工业级多表联查、窗口函数与索引优化
数据库·sql
ai_coder_ai10 小时前
论 NoSQL 数据库技术及其应用
数据库·nosql