基本信息:
系统一:CentOS7.5 + mysql5.7.25
系统二:win10 + mysql5.7.25解压缩版
数据库表结构如下:
对MySql进行操作时报以下错误:
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘information_schema.PROFILING.SEQ‘ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
一次性解决方案:
1. 查看sql_mode配置
select @@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
2. 修改sql_mode配置
2.1 编辑 vi /etc/my.cnf 文件
windwos环境下,直接修改默认my.ini(解压缩版)或其他默认配置文件即可
[root@VM_18_167_centos ~]# vi /etc/my.cnf
2.2 在my.cnf 里面设置 sql_mode
复制查询到的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
设置sql_mode内容如下:
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:
systemctl restart mysqld
再次执行插入语句,我们可以看到已经成功操作,不再报错了
原文地址:https://blog.51cto.com/1197822/2363459
时间: 2024-10-29 14:04:17