mysql异常ERROR 1055 (42000)说明
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql异常ERROR 1055 (42000)说明相关的知识,希望对你有一定的参考价值。
具体异常信息如下:
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'aaa.test.age' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
执行这样的SQL语句可重现异常 select age, name from test group by name
mysql5.1,不报异常
mysql5.5,不报异常
mysql5.6,不报异常
mysql5.7.22,报异常(具体从5.7哪个版本开始还没有确定下来,网上有人说5.7.5)
mysql从5.7的某个版本开始调整了默认参数sql_mode值为:
mysql> show variables like 'sql_mode'; +---------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | Variable_name | Value | +---------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | 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>
其中ONLY_FULL_GROUP_BY就是影响了上面SQL语句是否报异常
解决方法:
1、改写SQL语句,毕竟上面的写法不是标准的SQL语句
2、登陆mysql服务器,执行以下命令,在global与session级都修改
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'; mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
3、结合第2种方法,在my.cnf文件中,指定sql_mode的值:
[mysqld] sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
注:2与3结合可不用重启服务器,且即使重启配置也依然有效。
以上是关于mysql异常ERROR 1055 (42000)说明的主要内容,如果未能解决你的问题,请参考以下文章
docker拉取MySQL(percona)运行GROUP BY语句出现ERROR(1055):42000 如何解决。
MySQL_group by报错 [ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause]
MySQL_group by鎶ラ敊 [ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause]
查询表中最新一期资产负债率 ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contain