当前位置: 代码迷 >> 综合 >> mysql5.7 group报错ERROR 1055 (42000): Expression #1
  详细解决方案

mysql5.7 group报错ERROR 1055 (42000): Expression #1

热度:7   发布时间:2023-12-12 01:39:45.0

ubuntu16.04  apache2.4 php7.0 mysql5.7

$order_goods=db('order_goods')->where('orderid','in',$_orderid_arr)->group('orderid')->having('id>0')->select();
echo db('order_goods')->getLastSql();exit;

输出结果

ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'orderid' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

 解决办法

1.查看sql_model参数

mysql -u root -p
SELECT @@GLOBAL.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 

然后 

set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

刷新

flush privileges;

 退出mysql

exit;

编辑mysql配置文件 

vi /etc/mysql/mysql.conf.d/mysql.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

重启mysql

service mysql restart

 完成。

注:service mysql reload 无用。

 

  相关解决方案