sql模式设置引起的问题解决办法

作者:??Redrose2100???? 时间:2024-01-17 03:38:16 

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

来源:https://juejin.cn/post/7097126458585251854

标签:sql,模式,设置
0
投稿

猜你喜欢

  • CSS网页布局避免滥用DIV元素

    2011-03-30 12:34:00
  • 使用Python pandas读取CSV文件应该注意什么?

    2022-06-26 16:05:50
  • Nodejs 连接 mysql时报Error: Cannot enqueue Query after fatal error错误的处理办法

    2024-01-15 11:47:34
  • 带你轻松接触 MySQL中损坏的MyISAM表

    2008-12-19 17:55:00
  • java学习指南之字符串与正则表达式

    2022-02-23 14:05:50
  • 浅谈numpy.where() 的用法和np.argsort()的用法说明

    2022-03-12 01:52:23
  • 使用递归删除树形结构的所有子节点(java和mysql实现)

    2024-01-12 23:22:16
  • 程序猿新手学习必备的Python工具整合

    2024-01-02 00:53:26
  • JavaScript ES6的新特性使用新方法定义Class

    2024-04-10 11:00:30
  • Python图像处理之图像的灰度线性变换

    2021-12-16 22:30:58
  • PPOCRLabel标注的txt格式如何转换成labelme能修改的json格式

    2021-08-31 06:01:45
  • Python递归函数 二分查找算法实现解析

    2021-06-22 05:58:38
  • form的submit方法和submit事件(onsubmit)

    2008-09-28 13:29:00
  • python实现词法分析器

    2022-09-12 15:03:18
  • Python中的list与tuple集合区别解析

    2023-01-13 11:05:23
  • Python将list元素转存为CSV文件的实现

    2022-03-14 20:15:00
  • 使用NumPy进行数组数据处理的示例详解

    2023-03-31 20:06:50
  • Python 数据可视化超详细讲解折线图的实现

    2023-06-06 14:49:18
  • python读取文件名并改名字的实例

    2021-03-19 12:45:37
  • 用asp编写类似搜索引擎功能的代码

    2008-10-23 15:55:00
  • asp之家 网络编程 m.aspxhome.com