数据库批量插入耗时过长问题rewriteBatchedStatements=true

文章目录


前言

今天在维护一个小项目时,发现使用mybatisplus批量插入10000条数据,耗时30秒。看了一下配置文件,发现mysql配置中没有添加rewriteBatchedStatements=true

yml 复制代码
rewriteBatchedStatements=true

完整配置

yml 复制代码
spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true
     username: root
     password: 123456
     driver-class-name: com.mysql.cj.jdbc.Driver

参数说明

  1. 基础连接参数
    useUnicode=true - 启用 Unicode 字符集支持
    characterEncoding=utf-8 - 设置字符编码为 UTF-8
  2. 日期时间处理
    zeroDateTimeBehavior=convertToNull - 当遇到零日期时间值时转换为 NULL,避免解析异常
  3. 布尔类型处理
    transformedBitIsBoolean=true - 将 BIT 类型字段转换为布尔类型
  4. 多查询支持
    allowMultiQueries=true - 允许在单个语句中执行多个 SQL 查询
  5. 安全相关
    useSSL=false - 禁用 SSL 连接(开发环境常用)
    allowPublicKeyRetrieval=true - 允许公钥检索(MySQL 8.0+ 必需)
  6. 性能优化
    rewriteBatchedStatements=true - 重写批处理语句以提高性能,将多条 INSERT/UPDATE 语句合并为多值语句

相关推荐
百结2144 小时前
Mysql数据库操作
数据库·mysql·oracle
keep one's resolveY5 小时前
时区问题解决
数据库
Leinwin5 小时前
OpenClaw 多 Agent 协作框架的并发限制与企业化规避方案痛点直击
java·运维·数据库
qq_417695055 小时前
机器学习与人工智能
jvm·数据库·python
漫随流水5 小时前
旅游推荐系统(view.py)
前端·数据库·python·旅游
ego.iblacat5 小时前
MySQL 服务基础
数据库·mysql
Maverick067 小时前
Oracle Redo 日志操作手册
数据库·oracle
攒了一袋星辰7 小时前
高并发强一致性顺序号生成系统 -- SequenceGenerator
java·数据库·mysql
W.D.小糊涂7 小时前
gpu服务器安装windows+ubuntu24.04双系统
c语言·开发语言·数据库
云贝教育-郑老师8 小时前
【OceanBase 的多租户架构是怎样的?有什么优势?】
数据库·oceanbase