MySQL-[Err] 1055 - Expression #1
© 版权声明:本文为博主原创文章,转载请注明出处
问题描述:在MySQL数据库下,执行SQL插入语句报错。错误信息如下:

错误原因:在MySQL5.7之后,sql_mode中默认存在ONLY_FULL_GROUP_BY,SQL语句未通过ONLY_FULL_GROUP_BY语义检查所以报错。
ONLY_FULL_GROUP_BY:ONLY_FULL_GROUP_BY要求select语句中查询出来的列必须是明确的(其他语句也是一样)。
以SQL语句select columes from table group by list为例:columns必须是聚集函数或者在group by后的表达式list中,并且list中必须包含主键,否则也会报错。
insert、update、delete语句都会报错(但不影响SQL语句的执行),因为这三种语句执行之前也会执行查询操作。
以主键为id的表为例:
SELECT count(1) FROM customer GROUP BY `name`;该SQL执行成功,因为count是聚集函数;
SELECT * FROM customer GROUP BY `name`;该SQL执行失败,因为*中包含主键id,而group by后的表达式中并没有包含id
SELECT name FROM customer GROUP BY `name`;该SQL执行成功,因为name包含在group by后的表达式中
SELECT name, contact FROM customer GROUP BY `name`;该SQL执行失败,因为contact没有包含在group by后的表达式中
解决方案:
一、永久解决
1)在MySQL下执行SELECT @@sql_mode语句

2)将查询结果中的ONLY_FULL_GROUP_BY去掉然后复制,打开MySQL的配置文件,将sql_mode的值设置为复制的值
(若没有sql_mode在[mysqld]下方添加一行即可)。
MySQL配置文件所在位置:安装版可通过windows服务所对应mysql启动项,查看其对应属性->可执行文件路径,获取my.ini路径。
免安装版一般在其根目录下。(默认是my-default.ini,必须将名字改为my.ini才能生效)

3)重新MySQL服务即可生效
二、只在当前会话中解决,重新进入MySQL后失效
1)在MySQL下执行SELECT @@sql_mode语句

2)将查询结果中的ONLY_FULL_GROUP_BY去掉然后复制,然后执行set sql_mode = '修改后的值'

三、只在当前服务中解决,重新MySQL服务后失效
1)解决方式同方法二,只是在select和set时添加global关键字。具体可查看下图

MySQL-[Err] 1055 - Expression #1的更多相关文章
- MySQL [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause
MySQL[Err]1055 上次MySQL5.7.19主从建立完成之后,所有的测试都是在MySQL命令行下进行的,最近用Navicat Premium进行MySQL的连接,然后在插入数据的时候MyS ...
- 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 GRO
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated c ...
- mysql主给备赋予权限时报错,MySQL [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause
https://www.cnblogs.com/skymyyang/p/7551646.html 在my.cnf 里面设置sql_mode='STRICT_TRANS_TABLES,NO_ZERO_I ...
- [bug]MySQL [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause
参考 http://www.10qianwan.com/articledetail/220315.html
- mysql错误:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated
今天迁移django数据库的时候,跑程序的时候出现这样的错误: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY cla ...
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL
问题:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregate ...
- Mysql err 1055
目录: 错误信息 原因分析 解决方案 操作示例 错误信息 [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause ...
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ'
在Navicat Premium中执行Mysql的一条删除语句,虽然执行成功了,却提示已下错误: 受影响的行: 时间: .005s of ORDER BY clause is not in GROUP ...
- MySQL5.7.27报错[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated
mysql5.7.27在运行更新语句时出现如下情况,mysql5.6之前没有这种情况出现. of ORDER BY clause is not in GROUP BY clause and conta ...
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题
问题: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregat ...
随机推荐
- .net开发工具集合
原文发布时间为:2010-10-24 -- 来源于本人的百度文章 [由搬家工具导入] 原文出处:.NET Tools:Ten Must-Have Tools Every Developer Shoul ...
- 改变querystring值,然后重定向
原文发布时间为:2009-11-13 -- 来源于本人的百度文章 [由搬家工具导入] 本页面改变querystring值,然后重定向 本页面,避免出现重复querystring。。 如避免出现 www ...
- VBCodeProvider .net compiler service interface or something like that
https://msdn.microsoft.com/zh-cn/library/microsoft.visualbasic.vbcodeprovider%28v=vs.110%29.aspx ref ...
- luogu 3406 海底高铁 前缀和
题目链接 题意 给定一个数轴上的若干城市\(1,2,3,...,n\),在第\(i\)到\(i+1\)\((1\leq i\lt n)\)个城市间有铁路,通行方式可为 \(1.\)每次买票(花费\(a ...
- Windows消息钩取
@author: dlive @date: 2016/12/19 0x01 SetWindowsHookEx() HHOOK SetWindowsHookEx( int idHook, //hook ...
- 语法错误: 标识符“__RPC__out_xcount_part” 解决方法
1.错误描述 2.解决方案:将 $(DXSDK_DIR)\Include; 放到最后面,如下
- 【Visual Studio】无法打开包括文件:“SDKDDKVer.h”
解决办法是在头文件的搜索目录中添加$(WindowsSDK_IncludePath);,同时在库文件的搜索目录中添加$(WindowsSDK_LibraryPath_x86);
- C语言字符串操作总结大全(超详细)【转】
转自:http://www.jb51.net/article/37410.htm )字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strc ...
- C++学习(一):现代C++尝试
C++是一门与时俱进的语言. 早期的C++关注的主要问题是通用性,却没有太多关注易用性的问题,使得C++成为了一门多范式语言,但是使用门槛较高. 从2011开始,C++的标准进行了较大的更新,开始更多 ...
- nodejs编写实例基础操作
学习视频地址 https://cnodejs.org/topic/5a72c66ace45d440451465c3 初始化项目 首先查看项目中是否有package.json 文件,如果有可执行np ...