研发发来了一个报错,这个报错是sql_mode=only_full_group_by兼容性导致。直接修改sql_mode就可以了。

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'xxx.bm.gid'; this is incompatible with sql_mode=only_full_group_by
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_152]
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_152]
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_152]
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_152]

临时修改

## 查看
-- 开启-- 查看数据库版本和 Session级信息
SELECT VERSION(),@@sql_mode;
-- 查看数据库版本和 GLOBAL级信息
SELECT VERSION(),@@GLOBAL.sql_mode;


## 关闭
-- 关闭 session级
SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

-- 关闭 GLOBAL级
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

查看线上配置
2024-08-13T02:08:06.png

修改配置文件

  mysql:
    image: harbor.op123.ren:44301/library/mysql:5.7.35
    command: --sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
    restart: "no"
    container_name: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=xxx
      - TZ=Asia/Shanghai
      - SET_CONTAINER_TIMEZONE=true
      - CONTAINER_TIMEZONE=Asia/Shanghai
      # 添加性能相关的环境变量
      - MYSQL_INNODB_BUFFER_POOL_SIZE=4G
      - MYSQL_INNODB_LOG_FILE_SIZE=256M
      - MYSQL_INNODB_LOG_BUFFER_SIZE=64M
      - MYSQL_INNODB_FLUSH_LOG_AT_TRX_COMMIT=2
      - MYSQL_INNODB_FLUSH_METHOD=O_DIRECT
      - MYSQL_MAX_CONNECTIONS=1000
      # 添加日志相关的环境变量
      - MYSQL_LOG_CONSOLE=true
      - MYSQL_LOG_ERROR=/var/log/mysql/custom-error.log
      - MYSQL_LOG_QUERIES_ENABLED=true
      - MYSQL_LOG_QUERIES_FILE=/var/log/mysql/queries.log
    networks:
      yewu-network:
        ipv4_address: 192.168.177.55
    cap_add:
      - SYS_NICE  # CAP_SYS_NICE
    ports:
      - 3306:3306
    volumes:
      - ./data/mysql/conf:/etc/mysql/conf.d
      - ./data/mysql/data:/var/lib/mysql
      - ./data/mysql/logs:/var/log/mysql
      - /etc/localtime:/etc/localtime:ro
    # 添加资源限制
    deploy:
      resources:
        limits:
          cpus: '4'
          memory: 8G
        reservations:
          cpus: '4'
          memory: 8G
最后修改:2024 年 08 月 13 日
如果觉得我的文章对你有用,请随意赞赏