错误:[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
原因是 mysql5.7以上 sql_mode默认有ONLY_FULL_GROUP_BY ,可以使用
show variables like '%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
解决方法:
删除ONLY_FULL_GROUP_BY,修改mysql默认配置, 配置文件路径/etc/mysql/mysql.conf.d/mysqld.cnf,在文件最后加入:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION