记一次,在迁移服务的时候,连上新的数据库,数据库也是备份的以前的,发现报错:
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'datacn_store.sod.goods_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
开始以为是导入的时候编码什么的不对,后来网上查资料发现是mysql版本问题,现记录一下:
MySQL 5.7.5后only_full_group_by成为sql_mode的默认选项之一,这可能导致一些sql语句失效。
解决方法
-
把group by字段
group_id
设成primary key 或者 unique NOT NULL。这个方法在实际操作中没什么意义。 -
使用函数
any_value
把报错的字段name
包含起来。如,select any_value(name), group_id from game group by group_id
。 -
在配置文件my.cnf中关闭sql_mode=ONLY_FULL_GROUP_BY.。msqyl的默认配置是
sql_mode=ONLY_FULL_GROUP_BY,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
去掉,也可以去掉所有选项设置成sql_mode=
,如果你确信其他选项不会造成影响的话。
本人用的第二种方法,已解决。
参考文章:https://www.cnblogs.com/fswhq/p/9729761.html