ONLY_FULL_GROUP_BY
select * from cnarea_2019 group by parent_code;
含义 sql中group by后面的字段必须出现在select后面,或者被聚合函数包裹,不然会抛出如下错误
1 | Error Code: 1055. Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘×××’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by |
临时解决办法
在查询前先执行下面任意一种:
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));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';
此方案为会话级别,重新连接数据库时失效。
终极解决办法
通过执行mysql --help可以获取配置文件读取路径
1 | Default options are read from the following files in the given order: |
即为以上任意位置建立my.ini配置文件都会被mysql服务读取。配置内容如下:
1 | [mysql] |
重启mysql服务即可永久生效。