mysql高版本ONLY_FULL_GROUP_BY,的问题

问题描述

打开mysql,输入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等值,其中第一项即为ONLY_FULL_GROUP_BY。该值会导致mysql在进行GROUP BY的时候,报错,错误信息如下:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.employe.employeeid' 
which is not functionally dependent on columns in GROUP BY clause;
 this is incompatible with sql_mode=only_full_group_by

上图为按照employee表中的employeeid进行分组时所报的错误信息

解决方法

到mysql的安装目录下,找到my.ini文件,如果没有该文件,则一定有my-default.ini文件,将my-default.ini改名为my.ini,然后进行编辑,在[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,问题解决

你可能感兴趣的:(sql)