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

相关推荐
weixin_307779131 小时前
VS Code配置MinGW64编译SQLite3库
开发语言·数据库·c++·vscode·算法
SelectDB2 小时前
Apache Doris 4.0 AI 能力揭秘(一):AI 函数之 LLM 函数介绍
数据库·人工智能·数据分析
我是哈哈hh2 小时前
【MySQL】在UBuntu环境安装以及免密码登录入门
linux·数据库·mysql·ubuntu
HeyZoeHey2 小时前
Mybatis执行sql流程(一)
java·sql·mybatis
喪彪3 小时前
MySQL新手教学
数据库·mysql·adb
Q_Q19632884755 小时前
python的电影院座位管理可视化数据分析系统
开发语言·spring boot·python·django·flask·node.js·php
丘大梨5 小时前
QT 基础聊天应用项目文档
运维·数据库·系统架构
HMBBLOVEPDX6 小时前
MySQL的多版本并发控制(MVCC):
数据库·mysql·mvcc
.用户昵称已存在.6 小时前
MongoDB 从入门到精通:安装配置与基础操作指令详解
数据库·mongodb