zoukankan      html  css  js  c++  java
  • mysql下this is incompatible with sql_mode=only_full_group_by解决方案

    本地测试没有问题,部署到客户服务器之后报如下错误:

    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘testID’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

    这个错误的原因是高版本mysql(客户服务器版本是5.7.18)默认的sql_mode包含ONLY_FULL_GROUP_BY,这个属性保证了select到的列都在group by中出现。 
    查看sql_mode的语句如下:

    select @@GLOBAL.sql_mode;
    • 1

    可以使用sql语句暂时修改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
    • 1

    然而重启mysql数据库之后,ONLY_FULL_GROUP_BY又出现了,顺便写下重启数据库命令:

    service mysqld stop
    service mysqld start
    • 1
    • 2

    所以需要修改mysql配置文件,通过手动添加sql_mode的方式强制指定不需要ONLY_FULL_GROUP_BY属性,my.cnf位于etc文件夹下,vim下光标移到最后,添加如下:

    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

    重启后问题解决。

  • 相关阅读:
    #Leetcode# 700. Search in a Binary Search Tree
    很多很多书上代码
    #Leetcode# 104. Maximum Depth of Binary Tree
    #Leetcode# 12. Integer to Roman
    PAT-2018年冬季考试-乙级
    PAT 1035 插入与归并
    PAT 1058 选择题
    PAT 1052 卖个萌
    CodeForces Round #521 (Div.3) E. Thematic Contests
    2017Nowcoder Girl初赛重现赛
  • 原文地址:https://www.cnblogs.com/wangmo/p/9018279.html
Copyright © 2011-2022 走看看