前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL多语句执行测试

MySQL多语句执行测试

原创
作者头像
胖五斤
发布2023-09-19 10:53:39
2870
发布2023-09-19 10:53:39
举报

测试目的

验证MySQL数据库在java应用jdbc参数不同配置情况下的表现。

测试程序

通过配置文件,确定不同的jdbc参数组合:

测试结论

mysql

rewriteBatchedStatements

False

False

True

True

allowMultiQueries

False

True

False

True

批量insert(batch statements)

正常

正常

正常

正常

多条sql(multi query)

报错

正常

报错

正常

建议

需要用分号,多条sql提交执行的时候,jdbc参数设置allowMultiQueries=true

测试过程

详细如下:

JDBC:rewriteBatchedStatements=false&allowMultiQueries=false

测试程序报错:(批量写入正常,多语句执行报错)

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select count(*) from tinsert;insert into tinsert (id,a) values(0,1),(0,2);select' at line 1;

general_log看到:批量insert语句,实际上客户端分成多条发起请求;

JDBC:rewriteBatchedStatements=false&allowMultiQueries=true

程序正常执行无报错。

JDBC:rewriteBatchedStatements=true&allowMultiQueries=false

测试程序报错:(批量写入正常,多语句执行报错)

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select count(*) from tinsert;insert into tinsert (id,a) values(0,1),(0,2);select' at line 1;

JDBC:rewriteBatchedStatements=true&allowMultiQueries=true

程序正常执行无报错。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 测试目的
  • 测试程序
  • 测试结论
    • 建议
      • 测试过程
        • JDBC:rewriteBatchedStatements=false&allowMultiQueries=false
        • JDBC:rewriteBatchedStatements=true&allowMultiQueries=false
    相关产品与服务
    云数据库 MySQL
    腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档