mysql 8.0 this is incompatible with sql_mode=only_full_group_by
时间: 2023-10-15 21:25:02 浏览: 194
当使用MySQL 8.0版本时,如果配置文件中的sql_mode参数包含only_full_group_by,那么在使用GROUP BY语句查询时可能会出现错误,错误信息可能是"Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column"。这是因为在GROUP BY后的查询字段与SELECT列表中的字段不一致导致的,而MySQL 5.7.5及以上版本才会报这个错误。
解决这个问题的办法是查看sql_mode配置,在命令行输入"SELECT @@GLOBAL.sql_mode;"可以查看当前的sql_mode字符串。复制查询结果字符串并去掉其中的only_full_group_by参数,例如"STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"。然后找到MySQL配置文件my.cnf,一般在/etc/my.cnf路径,也可能在其他自定义路径。进入配置文件,找到[mysqld]下的sql-mode参数,将复制的查询结果字符串添加到sql-mode参数中,保存并重启MySQL服务。
如果你使用的是docker安装的MySQL,可以直接使用"docker restart 容器id"重启容器。
综上所述,当使用MySQL 8.0版本出现"this is incompatible with sql_mode=only_full_group_by"的错误,可以通过修改配置文件中的sql_mode参数来解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [mysql8.0 this is incompatible with sql_mode=only_full_group_by](https://blog.csdn.net/u014041769/article/details/107209176)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Mysql group by 查询报错 1055 this is incompatible with sql_mode=only_full_group_by](https://blog.csdn.net/weixin_43721000/article/details/130423838)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [解决MySQL 5.7.9版本sql_mode=only_full_group_by问题](https://download.csdn.net/download/weixin_38697063/13699570)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文