Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:

 

错误

报错如下:

Error querying database.  Cause: : com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression 
#2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'temp.applyinstId' which is not functionally 
dependent on columns in GROUP BY clause; 
this is incompatible with sql_mode=only_full_group_by

重点是:

this is incompatible with sql_mode=only_full_group_by

原因

这个错误是mysql 5.7 版本及以上版本会出现的问题:

  • mysql 5.7版本默认的sql配置是:sql_mode=“ONLY_FULL_GROUP_BY”,这个配置严格执行了"SQL92标准"。

在sql执行时:

  • 输出的结果是叫target list,就是select后面跟着的字段,还有一个地方group by column,就是 group by后面跟着的字段。由于开启

ONLY_FULL_GROUP_BY

   的设置,所以如果一个字段没有在target list 和group by字段中同时出现,或者是聚合函数的值的话,那么这条sql查询是被mysql认为非法的,会报错误。

解决

1、临时

修改sql_mode:

set @@GLOBAL.sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

但是这种方式每次重启,sql_mode又会初始化。

2、彻底

修改mysql配置文件my.ini:

在 [mysqld]下添加:

 sql_mode =STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION;

参考:

【1】:https://blog.csdn.net/qq_42175986/article/details/82384160

【2】:https://www.cnblogs.com/jim2016/p/6322703.html

【3】:https://blog.csdn.net/sinat_40770656/article/details/101198274

【4】:https://blog.csdn.net/liuyongyuan2012/article/details/81946388

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4天前
|
SQL 搜索推荐 关系型数据库
Mysql报Cause: java.sql.SQLException: Incorrect string value: ‘\xE5\xA4\x96‘...for column username
Mysql报Cause: java.sql.SQLException: Incorrect string value: ‘\xE5\xA4\x96‘...for column username
27 0
|
11月前
|
程序员 数据库
Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 操作数类型冲突: varbinary 与 text 不兼容
Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 操作数类型冲突: varbinary 与 text 不兼容
850 0
|
11月前
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column
56 0
|
SQL 关系型数据库 MySQL
一次org.springframework.jdbc.BadSqlGrammarException ### Error querying database Cause: com.mysql.jdbc....
一次org.springframework.jdbc.BadSqlGrammarException ### Error querying database Cause: com.mysql.jdbc....
548 0
|
关系型数据库 MySQL
org.apache.ibatis.exceptions.PersistenceException: ###Error querying database. Cause: com.mysql.jd
原因:mysql的驱动包mysql-connector-java-x.x.x-bin.jar没导对
72 0
|
Java 数据库连接 数据库
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is jav
数据库连接超时,是数据库连接时的相关配置写错,例如:数据库密码,驱动等问题
3221 0
|
关系型数据库 MySQL
mysql 执行查询导致服务器崩溃求解:Some pointers may be invalid and cause the dump to abort
120720  9:25:25  InnoDB: Assertion failure in thread 1175046464 in file row/row0mysql.c line 1534 InnoDB: Failing assertion: index->type & DICT_C...
2905 0
|
4天前
|
SQL Java 关系型数据库
MySQL之JDBC(二)
MySQL之JDBC(二)
36 0
|
4天前
|
关系型数据库 MySQL Java
MySQL之JDBC(一)
MySQL之JDBC
35 0
|
4天前
|
关系型数据库 MySQL Java
MySQL的主从复制 && SpringBoot整合Sharding-JDBC解决读写分离
MySQL的主从复制 && SpringBoot整合Sharding-JDBC解决读写分离
39 0

推荐镜像

更多