mysql 报错:only_full_group_by 或者 sql_mode=only_full_group_by

报错信息:

[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'green_sd_gyl_test.t_pharmacy_shop_order.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

 

-- 1 查询版本
select version(); 


-- 查询mysql 安装路径
select @@basedir as basePath from dual 

 

 

-- 2.查看sql_model参数命令: 

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

 

SELECT @@SESSION.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

 


3.解决方法:编辑mysql配置文件 my.cnf

或者是my.ini

(亲测成功)

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

在 [mysqld]下添加

[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

重启mysql即可

你可能感兴趣的:(数据库)