问题出现情况
按照客户要求把我们平时使用的云数据库迁移到在客服服务器上装的Mysql,其他一切良好,运行某个包含Group by 语句的时候出现以下错误
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Expression #1 of SELECT list is not in GROUP BY clause
and contains nonaggregated column 'xxxxxx' which is not
functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by
以面向baidu 的编程思想得知此问题是因为mysql5.7,MySql默认启用了only_full_group_by SQL模式
通过在/etc/my.conf最后加上:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
后重启服务 测试发现解决
回头有时间会专门对only_full_group_by 模式进行研究