mysql 5.7.19 插入数据异常,异常如下:
1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column
'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by
方法二:
1.查看sql_mode
SELECT @@sql_mode
SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.sql_mode;
查询出来的值为:ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
2.去掉ONLY_FULL_GROUP_BY,重新设置值
set @@global.sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))
或
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
3.上面是改变了全局sql_mode,对于新建的数据库有效。对于已存在的数据库,则需要在对应的数据下执行:
set sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))
或
set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
注:方法二修改完成后,如果你重启Mysql服务的话,发现ONLY_FULL_GROUP_BY还是会存在的。推荐使用方法一