mysql报错1200_Mac MySql8报错1055 - Expression #3 of SELECT list is not in GROUP BY clause and contains n...

报错信息:

1055 - Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘fbjs.mscc.ContactTime’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by, Time: 0.000000s

报错原因:

在mysql5.7以上的版本中,对于 group by 的这种聚合操作,如果在select 中的列,没有在group by 中出现,那么这个SQL是不合法的,因为列不在group by的从句中,所以对于设置了这个mode的数据库,在使用group by 的时候,就要用MAX(),SUM(),ANT_VALUE()的这种聚合函数,才能完成GROUP BY 的聚合操作。

解决方法:

方法一:修改sql语句

把所有除了有聚合函数的字段都加在select后面的查询结果里。

方法二:修改数据库临时配置

执行sql语句:

set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

方法三:修改数据库配置文件

修改/etc/my.cnf,将sql_mode=中的only_full_group_by给删掉

如果没有my.cnf文件则创建一个,mysql的配置文件路径查找优先级为/etc/my.cnf,/etc/mysql/my.cnf,/usr/local/etc/my.cnf,通过Homebrew安装的my.cnf放在/usr/local/etc/中。

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# socket = .....

#服务端口号 默认3306

port = 3306

server_id = 1

# mysql安装根目录

basedir = /usr/local/mysql

# mysql数据文件所在位置

datadir = /usr/local/mysql/data

# pid

#pid-file = /usr/local/mysql/data/mysql.pid

# 设置socke文件所在目录

#socket = /usr/local/mysql/data/mysql.sock

# 跳过密码登录

# skip-grant-tables

# 数据库默认字符集,主流字符集支持一些特殊表情符号(特殊表情符占用4个字节)

# character-set-server = utf8mb4

# 数据库字符集对应一些排序等规则,注意要和character-set-server对应

# collation-server = utf8mb4_general_ci

# 设置client连接mysql时的字符集,防止乱码

# init_connect='SET NAMES utf8mb4'

# 是否对sql语句大小写敏感,1表示不敏感,8.0需要在初始化时候设置

# lower_case_table_names = 1

# 最大连接数

max_connections = 1000

#最大错误连接数

max_connect_errors = 1200

# wait_timeout = 1814400

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

# 二进制日志目录

#log_bin = /usr/local/mysql/logs/mysql-bin

# 自动删除过期日志的天数

expire_logs_days = 10

# 限制单个文件大小

max_binlog_size = 100M

# 查询日志

#general_log = 1

# 查询日志文件位置

#general_log_file = /usr/local/mysql/logs/query.log

# 数据库错误日志文件

#log_error = /usr/local/mysql/logs/error.log

# sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

给新创建的my.cnf授权644权限

chmod 644 /etc/my.cnf

修改mysql配置

6710812bc7adcc73514bf48f0da4a748.png

重启mysql服务

f84356e9daffd8d1fc49e1e63f96f949.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用:1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'senior_two.score.student_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 。 引用:这个错误是由于 MySQL 的新版本中默认开启了ONLY_FULL_GROUP_BY模式,即在 GROUP BY 语句中的 SELECT 列表中,只能包含分组或聚合函数,不能包含其他列。而你的查询语句中出现了一个列senior_two.score.student_id,它既没有被分组也没有被聚合,因此 MySQL 报出了这个错误。 。 引用:如果启用了only_full_group_by SQL模式(在默认情况下是这样),那么MySQL就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。(在5.7.5之前,MySQL没有检测...。 根据引用,这个错误意味着在SELECT语句中的第二个表达式不在GROUP BY子句中,并且包含了一个非聚合的列'senior_two.score.student_id'。这与sql_mode=only_full_group_by模式不兼容。 根据引用,这个错误是由于MySQL的新版本中默认开启了ONLY_FULL_GROUP_BY模式。在GROUP BY语句的SELECT列表中,只能包含分组或聚合函数,不能包含其他列。而你的查询语句中出现了一个列'senior_two.score.student_id',它既没有被分组也没有被聚合,因此MySQL报出了这个错误。 如果你启用了only_full_group_by SQL模式(默认情况下是启用的),那么MySQL会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘se](https://blog.csdn.net/m0_61615803/article/details/130076452)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains ...](https://download.csdn.net/download/weixin_38743076/13698627)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值