MySQL sql模式设置引起的问题


Posted in MySQL onMay 15, 2022

1 报错类似如下

数据库错误: Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Expression 39 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.ss.student_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
The error may exist in URL [jar:file:/usr/local/xxxxx.jar!/BOOT-INF/lib/summer-system-4.6.0.jar!/mapper/system/SuOrgProgramMapper.xml]
The error may involve com.ruoyi.system.mapper.SuOrgProgramMapper.selectSuOrgProgramList-Inline
The error occurred while setting parameters
SQL: select sop.*,so.org_name as orgName,sa.activity_name as activityName,sa.activity_name_en as activityNameEN,         ss.student_id as matchedStudentId,ss.name as matchedStudentName, su.login_name as email, su.real_name AS firstName, su.nickname as nickname         from su_org_program sop         inner join su_activity sa on sop.activity_id=sa.activity_id         inner join su_org so on so.org_id = sop.org_id         left JOIN sys_user su ON sop.main_teacher_id = su.sub         left join (select * from su_student_program where is_matched=1) ssp on ssp.org_program_id= sop.org_program_id         left JOIN su_student ss on ssp.student_id=ss.student_id          WHERE  sop.org_id = ?          GROUP BY sop.org_program_id
Cause: java.sql.SQLSyntaxErrorException: Expression 39 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.ss.student_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by\n; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression 39 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.ss.student_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

2 解决办法

2.1 查看全局sql模式

使用如下m命令:

select @@global.sql_mode;

如下:

mysql> select @@global.sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@global.sql_mode                                                                                                                         |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

2.2 设置全局sql模式

使用如下命令:

SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

如下:

ysql> SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>

2.3 查看当前sql模式

使用如下命令:

select @@sql_mode;

如下:

mysql> select @@sql_mode;
+------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                             |
+------------------------------------------------------------------------------------------------------------------------+
| STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>

2.4 设置当前sql模式

使用如下命令:

set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

如下:

mysql> set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>

3 永久生效的解决办法

3.1 找到my.cnf文件

可以使用如下命令查找,一般在 /etc/下或者 /etc/mysql/ 目录下

find /etc/ -name my.cnf

3.2 编辑my.cnf文件

vi /etc/mysql/my.cnf

然后增加以下内容:

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

3.3 重启数据库服务

systemctl restart mysqld

到此这篇关于sql模式设置引起的问题解决办法的文章就介绍到这了,更多相关sql模式设置内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!


Tags in this post...

MySQL 相关文章推荐
MySQL分库分表与分区的入门指南
Apr 22 MySQL
MySQL sql_mode修改不生效的原因及解决
May 07 MySQL
MySQL索引知识的一些小妙招总结
May 10 MySQL
MySQL 8.0 Online DDL快速加列的相关总结
Jun 02 MySQL
解决mysql模糊查询索引失效问题的几种方法
Jun 18 MySQL
MySQL REVOKE实现删除用户权限
Jun 18 MySQL
QT连接MYSQL数据库的详细步骤
Jul 07 MySQL
一文弄懂MySQL索引创建原则
Feb 28 MySQL
MySQL数据库如何使用Shell进行连接
Apr 12 MySQL
MySQL存储过程及语法详解
Aug 05 MySQL
MySQL 原理与优化之原数据锁的应用
Aug 14 MySQL
MySQL 原理与优化之Update 优化
Aug 14 MySQL
MySQL 逻辑备份 into outfile
May 15 #MySQL
Mysql开启外网访问
May 15 #MySQL
Mysql索引失效 数据库表中有索引还是查询很慢
MySQL查询日期时间
May 15 #MySQL
MySQL 数据库 增删查改、克隆、外键 等操作
May 11 #MySQL
MySQL 计算连续登录天数
May 11 #MySQL
mysql 获取相邻数据项
May 11 #MySQL
You might like
php使用websocket示例详解
2014/03/12 PHP
ThinkPHP中limit()使用方法详解
2016/04/19 PHP
PHP实现websocket通信的方法示例
2018/08/28 PHP
php 中phar包的使用教程详解
2018/10/26 PHP
PHP代码加密的方法总结
2020/03/13 PHP
Jquery.TreeView结合ASP.Net和数据库生成菜单导航条
2010/08/27 Javascript
基于JQuery的6个Tab选项卡插件
2010/09/03 Javascript
简略说明Javascript中的= =(等于)与= = =(全等于)区别
2013/04/16 Javascript
js的image onload事件使用遇到的问题
2014/07/15 Javascript
JavaScript Serializer序列化时间处理示例
2014/07/31 Javascript
node-webkit打包成exe文件被360误报木马的解决方法
2015/03/11 Javascript
鼠标事件的screenY,pageY,clientY,layerY,offsetY属性详解
2015/03/12 Javascript
简单实现异步编程promise模式
2015/07/31 Javascript
jQuery position() 函数详解以及jQuery中position函数的应用
2015/12/14 Javascript
JS组件Bootstrap ContextMenu右键菜单使用方法
2016/04/17 Javascript
Vue中用props给data赋初始值遇到的问题解决
2018/11/27 Javascript
微信小程序实现下拉框功能
2019/07/16 Javascript
Vue中import from的来源及省略后缀与加载文件夹问题
2020/02/09 Javascript
JQuery省市联动效果实现过程详解
2020/05/08 jQuery
vue项目中openlayers绘制行政区划
2020/12/24 Vue.js
微信小程序实现简单购物车功能
2020/12/30 Javascript
Python工厂函数用法实例分析
2018/05/14 Python
Python查看微信撤回消息代码
2018/06/07 Python
五种Python转义表示法
2020/11/27 Python
Python实现给PDF添加水印的方法
2021/01/25 Python
使用CSS3实现一个3D相册效果实例
2016/12/03 HTML / CSS
微软加拿大官方网站:Microsoft Canada
2019/04/28 全球购物
应届生会计电算化求职信
2013/10/03 职场文书
专科毕业生自我鉴定
2013/12/01 职场文书
高中军训广播稿
2014/01/14 职场文书
法学专业毕业实习自我鉴定2014
2014/09/27 职场文书
共产党员批评与自我批评
2014/10/15 职场文书
行政人事主管岗位职责
2015/04/11 职场文书
golang协程池模拟实现群发邮件功能
2021/05/02 Golang
mysql 联合索引生效的条件及索引失效的条件
2021/11/20 MySQL
python神经网络 使用Keras构建RNN训练
2022/05/04 Python