不积跬步,无以至千里
博客
Python
Python
Flask
Django
FastAPI
设计模式(Python语言)
数据结构与算法(Python语言)
爬虫
数据分析
Java
Java
SpringBoot
SprintCloud
CC++
C语言
C++语言
Go
Go
设计模式(Go)
数据结构与算法(Go)
云计算
云计算理论
Linux
Shell
云原生
云原生理论
Docker
Kubernetes
Kubersphere
DevOps
Git
Gitlab
Jenkins
Nexus
Harbor
SonarQube
Grafana
OpenQA
建木
禅道
Compass-CI
前端
HTML
CSS
JavaScript
BootStrap
Vue
React
Markdown
数据库
MySql
Redis
MongoDB
H2 Database
Liquibase
ElasticStack
中间件
MQ
Kafka
Nginx
cpolar
阿里云
测试
测试理论
安全测试
压力测试
Pytest
UnitTest
考试
软考中级(软件设计师考试)
软考高级(系统架构设计师考试)
登录
注册
MySQL----MySQL中因为sql模式设置引起的问题解决办法
收藏本文
作者:redrose2100 类别:MySql 日期:2022-05-13 07:54:01 阅读:246 次 消耗积分:0 分
### 1 报错类似如下 ```bash 数据库错误: 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命令 ```bash select @@global.sql_mode; ``` 如下: ```bash 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模式 使用如下命令 ```bash SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; ``` 如下: ```bash 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模式 使用如下命令 ```bash select @@sql_mode; ``` 如下 ```bash 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模式 使用如下命令 ```bash set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; ``` 如下: ```bash 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/ 目录下 ```bash find /etc/ -name my.cnf ``` #### 3.2 编辑my.cnf文件 ```bash vi /etc/mysql/my.cnf ``` 然后增加以下内容: ```bash sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION ``` #### 3.3 重启数据库服务 ```bash systemctl restart mysqld ```
始终坚持开源开放共享精神,同时感谢您的充电鼓励和支持!
版权所有,转载本站文章请注明出处:redrose2100, http://blog.redrose2100.com/article/172
上一篇:
Kubernetes----Kubernetes集群环境搭建
下一篇:
Kubernetes----Kubernetes集群环境配置在Node节点或普通用户使用kubectl命令
你的昵称:
你的评论:
提示:登录后添加有效评论可享受积分哦!
点此登录
搜索
个人成就
DevOps技术交流微信群
加微信邀请进群
常用网站链接
开源软件洞察
云原生技术栈全景图
Python语言官方文档
Go语言官方文档
Docker官方文档
Jenkins中文用户手册
Markdown语法官方教程
Harbor官方文档
openQA官方文档
云原生开源社区
开源中国
Kubernetes中文文档
Kubernetes中文社区
Kubersphere官方文档
BootStrap中文网站
JavaScript中文网
NumPy官方文档
Pandas官方文档
GitLink确实开源网站
数据库排名网站
编程语言排名网站
SEO综合查询网站
数学加减法练习自动生成网站
Kickstart Generator
文章分类
最新文章
最多阅读
特别推荐
×
Close
登录
注册
找回密码
登录邮箱:
登录密码:
图片验证码:
注册邮箱:
注册密码:
邮箱验证码:
发送邮件
注册邮箱:
新的密码:
邮箱验证码:
发送邮件