MySQL sql_mode修改不生效的原因及解决
前言近期多次聊到sql_mode的话题,也是多次遇到相关问题,今天就趁热打铁,再给大家带来一个sql_mode的案例分享。场景模拟基于业务敏感性的考虑,下面涉及的表、存储过程等均非真实数据,但并不影响排查过程。(1)客户侧开发童鞋创建了一个存储过程,该存储过程没有严格遵守group by标准语法12345678910session 1:mysql> d
前言
近期多次聊到sql_mode的话题,也是多次遇到相关问题,今天就趁热打铁,再给大家带来一个sql_mode的案例分享。
场景模拟
基于业务敏感性的考虑,下面涉及的表、存储过程等均非真实数据,但并不影响排查过程。
(1)客户侧开发童鞋创建了一个存储过程,该存储过程没有严格遵守group by标准语法
1 2 3 4 5 6 7 8 9 10 |
|
(2)客户侧开发童鞋调用该存储过程,报错ERROR 1140;因为当时存储过程比较复杂,改造起来比较麻烦,所以客户侧选择修改sql_mode
1 2 3 |
|
(3)客户侧修改完sql_mode,再次执行,发现仍然报错ERROR 1140
1 2 3 4 5 6 7 |
|
(4)此时想到,修改系统变量,只对新建连接有效,对已有连接不起作用;于是,让客户侧重新建立连接,确认系统变量已生效,再次调用存储过程,但仍然报错ERROR 1140,重复尝试几次都是这个结果
1 2 3 4 5 6 7 8 9 10 11 |
|
(5)进一步排查,让客户侧在该会话,执行非标准的group by语句,发现可以正常执行
1 2 3 4 5 6 7 8 9 10 11 12 |
|
(6)继续排查发现,该存储过程的sql_mode,还是包括ONLY_FULL_GROUP_BY,因此执行报错
1 2 3 4 5 6 7 8 |
|
(7)这里我们也可以知道,系统变量修改只对新建对象有效,对已有对象不生效;解决办法很简单,重建该存储过程即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
总结
通过这个案例,我们可以知道,修改sql_mode系统变量,只对新建连接和新建对象(主要包括函数和存储过程)有效,对已有连接和已有对象不生效。
以上就是MySQL sql_mode修改不生效的原因及解决的详细内容
更多推荐
所有评论(0)