5

Mysql报错“this is incompatible with sql_mode=only_full_group_by”

 3 years ago
source link: https://www.daozhao.com/9992.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Mysql报错“this is incompatible with sql_mode=only_full_group_by”

如果您发现本文排版有问题,可以先点击下面的链接切换至老版进行查看!!!

Mysql报错“this is incompatible with sql_mode=only_full_group_by”

由于本站使用的是msyql8.x版本的mysql数据库,版本较高,发现网站的“月份存档”的数据不展示了,经过排查发现是接口未能如期返回的数据,而是出现了报错“this is incompatible with sql_mode=only_full_group_by”,显然是自己的sql语句里面有group_by,出现了兼容性问题。

我先进Mysql里面执行select @@GLOBAL.sql_mode;来查询下

41649638-DFFA-4977-A75A-EF8B92B279C1-300x43.jpg

我们可以这样解决这个问题

方法一:命令解决

执行命令:

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 重启后就会失效。

方法二:修改配置文件my.cnf

一般路径是 /etc/my.cnf,有的可能是推荐在/etc/my.cnf.d/这样的文件夹里面修改对应的*.cnf文件,这得看/etc/my.cnf里面配置。

通过在配置文件里面手动添加sql_mode的方式强制指定不需要ONLY_FULL_GROUP_BY属性,

[mysqld] 下面添加代码:

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

file

重启mysql,再次执行查询命令select @@GLOBAL.sql_mode;

file


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK