Mysql执行sql语句报错解决方法
1、 环境 介绍
数据库类型:mysql
数据库版本:5.7.26
2、 情景再现
执行建表语句报错
Create table t1(id int,name char(30)):
执行结果如下,表创建成功,但是会产生报错信息
[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_gr
3、 解决方法
(1)报错信息
今天在使用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”这样的错误,以前没有遇见过,现记录一下。
(2)修改配置文件
首先是在/etc/my.cnf配置文件的[mysqld] 下添加:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
(3)重启mysql服务方可生效
执行建表语句就不会报错。
Service mysql restart
Windows系统在服务管理器中找到mysql服务做重启操作即可。
4、 原因分析
通过查询众多资料获知,主要是由于sql_mode引起,所以先查看sql_mode没有配置,将告警的参数,编辑到MySQL的配置文件即可。