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 ...
随机推荐
- git refs 详解
https://blog.csdn.net/taiyangdao/article/details/52766424 http://www.chenchunyong.com/2017/01/06/git ...
- Linux硬链接和软链接(符号链接)
硬链接与软连接 :https://blog.csdn.net/u013777351/article/details/50557260 索引节点:https://blog.csdn.net/jessey ...
- svn提示出错异常为remains in conflict
查看原文:http://www.ibloger.net/article/225.html 提交冲突代码 commit -m "" E:/Program Files/MyEclips ...
- RocketMq使用注意事项
Topic 一个Topic是一个主题.一个系统中,我们可以将消息划成Topic,这样,将不同的消息发送到不同的queue. Queue 一个topic下,我们可以设置多个queue,每个queue就是 ...
- DataSet导出Excel,比以往的方法导出的Excel外观更加好看
原文发布时间为:2010-06-21 -- 来源于本人的百度文章 [由搬家工具导入] ======目前方法=========== #region 生成Excel/// <summary>/ ...
- [LeetCode] Number of 1 Bits 位操作
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- HttpClient 简介与使用
Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的 URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而 ...
- android程序入口
android程序的真正入口是Application类的onCreate方法
- 通过命令编译的项目 导入 到eclipse
通过命令编译的项目 导入 到eclipse后,需要 1.设置 sdk和ndk 的路径 2.设置 AndroidManifest.xml 中的版本为当前版本:<uses-sdk android:m ...
- Linux/Unix编程中的线程安全问题【转】
转自:http://blog.csdn.net/zhengzhoudaxue2/article/details/6432984 在目前的计算机科学中,线程是操作系统调度的最小单元,进程是资源分配的最小 ...