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

Jimin_Note·2022년 11월 17일
0

🌟nest.js

목록 보기
2/2
post-thumbnail

nestjs 프로젝트에서 service.ts을 npm start 후 POSTMAN으로 테스트를 해보던 도중 아래와 같은 에러를 만났다.

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'earth.Detection.createdAt' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

지금 사용 중인 mysql 버전이 5.7 인데 GROUP BY 사용하는 Query가 5.7부터는 안되는 것 같다.

공식문서 참고

MySQL 5.7.5 이상에서는 기능 종속성 감지를 구현합니다. ONLY_FULL_GROUP_BYSQL 모드가 활성화된 경우(기본적으로 활성화됨) MySQL은 선택 목록, 조건 또는 목록이 절에 이름이 지정되지 않았거나 기능적으로 종속되지 않은 집계되지 않은 열을 참조하는 쿼리 를 HAVING거부 합니다

그렇다고 GROUP BY를 사용하지 않을 수 없으니 sql_mode를 수정해주자.

sql_mode 조회

select @@sql_mode;

sql_mode 수정

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

my.cnf 수정

MAC에서 my.cnf 파일 위치 찾는 법

$ mysqld --verbose --help | grep -A 1 'Default options'

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /opt/homebrew/etc/my.cnf ~/.my.cnf `
  • /etc/my.cnf
  • /etc/mysql/my.cnf
  • ~/.my.cnf

my.cnf을 수정해야하는 데 나는 위 파일 모두 빈 파일로 나왔다..
그래서 결국 경로를 직접 타고 들어갔다.
나의 경우는 hombrew를 이용하여 mysql을 설치했었기 때문에
/opt/homebrew/etc/my.cnf

vim my.cnf
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
.
.
.

source my.cnf

결론

에러 해결!

profile
Hello. I'm jimin:)

0개의 댓글