본문 바로가기
Database/MySQL

[MySQL; 마이에스큐엘] 오류 / 에러 / this is incompatible with sql_mode=only_full_group_by

by daddydontsleep 2024. 6. 14.
728x90
728x90

사진: Unsplash 의 Tyler Nix

MySQL 5.7

org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db.a.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

5.7 버전에 sql_mode라는 항목이 생겼는데 그 옵션 중 only_full_group_by 때문에 발생하는 오류이다.

sql_mode

SELECT @@sql_mode;

sql_mode를 찾아보았다.

이제 `ONLY_FULL_GROUP_BY`를 없애보자.

1. 서버에서 작업하는 방법

vi /etc/my.cnf

[mysqld]
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=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

` ONLY_FULL_GROUP_BY` 를 빼주면 된다.

2. 연결된 세션에서 제거

SET SESSION sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

 

끝.

 

 

 

 

 

[reference]

MySQL :: MySQL 5.7 Reference Manual :: 12.19.3 MySQL Handling of GROUP BY

 

MySQL :: MySQL 5.7 Reference Manual :: 12.19.3 MySQL Handling of GROUP BY

12.19.3 MySQL Handling of GROUP BY SQL-92 and earlier does not permit queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are not named in the GROUP BY clause. For example, this query is illegal in sta

dev.mysql.com

[MySQL] sql_mode=only_full_group_by 에러 해결 방법 (tistory.com)

 

[MySQL] sql_mode=only_full_group_by 에러 해결 방법

여러 서비스의 MySQL을 사용하다 보면 MySQL Version(버전)을 이동하면서 사용하게 된다. 이때 5.6 Version / 5.7 Version 도 같이 사용되는 경우가 있거나, 혹은 서비스 데이터베이스(DB)가 5.6에서 5.7 Version으

info-lab.tistory.com

MySQL - How to turn off ONLY_FULL_GROUP_BY? | TablePlus

 

728x90
300x250