MySQL GROUP BY 报错

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/82892955 ...
+关注继续查看
版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/82892955

使用 GROUP BY 时抛出 only_full_group_by 异常

更多精彩

问题

  1. 通过 GROUP BY 查询时抛出下列异常
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxx' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

解决

  1. 设置全局 sql_mode
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';
  1. 查询设置结果 SELECT @@GLOBAL.sql_mode;
  2. 在可视化工具中通过 SET GLOBAL sql_mode 设置的结果只在会话中生效,数据库重启后则失效
  3. 想要设置 sql_mode 全局生效则需要在 mysql 的 my.cnf 文件中填写 sql_mode
  4. 通过 homebrew 安装 mysql 后,在 /etc 目录下默认没有创建 my.cnf 文件,需要自行创建 cp /usr/local/opt/mysql/support-files/my-default.cnf /etc/my.cnf
  5. 进入到 _etc_my.cnf 文件中,在最后输入 sql_mode
  6. 重启 mysql
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4天前
|
关系型数据库 MySQL
【XAMPP启动mysql报错】Port 3306 in use by ““C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld“……
【XAMPP启动mysql报错】Port 3306 in use by ““C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld“……
|
21天前
|
关系型数据库 MySQL 数据库
MySQL报错:Lock wait timeout exceeded; try restarting transaction
MySQL报错:Lock wait timeout exceeded; try restarting transaction
|
22天前
|
SQL druid 关系型数据库
MySQL连接超时时间wait_timeout导致间歇性报错:communication link failure
MySQL连接超时时间wait_timeout导致间歇性报错:communication link failure
|
26天前
|
Oracle 关系型数据库 MySQL
MySQL语句执行报错You can‘t specify target table for update in FROM clause
MySQL语句执行报错You can‘t specify target table for update in FROM clause
19 0
|
27天前
|
关系型数据库 MySQL Linux
jeecg-boot切换数据库mysql到postgresql报错:org.postgresql.util.PSQLException: 错误: 关系 “sched_name“ 不存在
jeecg-boot切换数据库mysql到postgresql报错:org.postgresql.util.PSQLException: 错误: 关系 “sched_name“ 不存在
|
28天前
|
关系型数据库 MySQL Linux
Linux下MySQL起动报错The server quit without updating PID file
Linux下MySQL起动报错The server quit without updating PID file
|
29天前
|
关系型数据库 MySQL
Mysql连接报错:1130-host ... is not allowed to connect to this MySql server
Mysql连接报错:1130-host ... is not allowed to connect to this MySql server
|
29天前
|
关系型数据库 MySQL 网络安全
Navicat for MySQL远程连接的时候报错mysql 1130的解决方法
Navicat for MySQL远程连接的时候报错mysql 1130的解决方法
|
2月前
|
关系型数据库 MySQL Windows
windows安装mysql报错Remove of the Service Denied!
windows安装mysql报错Remove of the Service Denied!
|
2月前
|
关系型数据库 MySQL Linux
mysql登录报错Can't create a new thread
mysql登录报错Can't create a new thread
推荐文章
更多