开发在查询数据时发现如下报错:
SQL 错误[1055] [42000]: Expression #1 of SELECT list is not in GROUP BY
clause and contains nonaggregated column 'table' which is not
functionally dependent on columns in GROUP BY clause: this is incompatible
with sql_mode=only_full_group_by
查询sql_mode发现有only_full_group_by模式
mysql> select @@sql_mode;
+------------------------------------------------------------------------------------------------------------------------+
| @@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 |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
执行下面的语句进行配置,全局去掉该模式。
mysql> 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';
centos系统到此问题已经解决。
但我用的ubantu,配置完成后发现并没有生效,ubantu需要直接使用配置文件修改。将my.cnf中的mysqld下加上下面的配置,重启MySQL后问题解决。
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
小白一枚,如有不实之处请各位大佬多多指点。