Mysql [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause

select version();
# 5.7.17

常规查询报错:
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column

Trouble shooting过程(注意mysql5.7配置文件的路径):

root@TESTDB:~# cd /
root@TESTDB:/# find -name my.ini
root@TESTDB:/# find -name my.cnf
./etc/alternatives/my.cnf
./etc/mysql/my.cnf
./var/lib/dpkg/alternatives/my.cnf
root@TESTDB:/# cat /etc/mysql/my.cnf
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
root@TESTDB:/# cat  /etc/mysql/conf.d/
cat: /etc/mysql/conf.d/: Is a directory
root@TESTDB:/# cd  /etc/mysql/conf.d/
root@TESTDB:/etc/mysql/conf.d# ll
total 12
drwxr-xr-x 2 root root 4096 May  8 19:29 ./
drwxr-xr-x 4 root root 4096 May  9 10:56 ../
-rw-r--r-- 1 root root  875 Nov 29 03:59 mysql.cnf
root@TESTDB:/etc/mysql/conf.d# cat mysql.cnf
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysql]
root@TESTDB:/etc/mysql/conf.d# cd /etc/mysql/mysql.conf.d/
root@TESTDB:/etc/mysql/mysql.conf.d# ll
total 12
drwxr-xr-x 2 root root 4096 May  9 10:55 ./
drwxr-xr-x 4 root root 4096 May  9 10:56 ../
-rw-r--r-- 1 root root 1212 May  8 19:36 mysqld.cnf
root@TESTDB:/etc/mysql/mysql.conf.d# cat mysqld.cnf
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
datadir     = /var/lib/mysql
log-error   = /var/log/mysql/error.log
lower_case_table_names=1
# By default we only accept connections from localhost
bind-address    = 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
############找到配置文件
root@TESTDB:/etc/mysql/mysql.conf.d# vim mysqld.cnf
############编辑配置文件,增加行:
############sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
root@TESTDB:/etc/mysql/mysql.conf.d# cat mysqld.cnf
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
datadir     = /var/lib/mysql
log-error   = /var/log/mysql/error.log
lower_case_table_names=1
# By default we only accept connections from localhost
bind-address    = 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
###########重启Mysql
root@TESTDB:/etc/mysql/mysql.conf.d# service mysql restart
 * Stopping MySQL Community Server 5.7.17
.....
 * MySQL Community Server 5.7.17 is stopped
 * Re-starting MySQL Community Server 5.7.17
..
 * MySQL Community Server 5.7.17 is started
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
、和[3]引用的内容都是关于MySQL报错1055的问题。这个错误是由于在使用ORDER BY子句时,ORDER BY子句中的列没有在GROUP BY子句中,并且包含了不是在GROUP BY子句中的列,这与sql_mode=only_full_group_by选项不兼容所导致的。换句话说,这个错误是由于使用了不合法的ORDER BY子句。 要解决这个问题,可以有以下几种方法: 1. 修改SQL查询语句,确保ORDER BY子句中的列都在GROUP BY子句中,并且不包含不在GROUP BY子句中的列。这样可以确保查询语句符合sql_mode=only_full_group_by选项的要求。 2. 修改MySQL配置文件,将sql_mode选项中的only_full_group_by选项去掉。这样可以关闭只允许全面GROUP BY的模式,但需要注意这可能会导致其他潜在的问题。 3. 升级MySQL版本到5.7.5或更高的版本。从MySQL 5.7.5开始,sql_mode=only_full_group_by成为默认设置,不再允许ORDER BY子句中的非聚合列。 请根据具体情况选择适合的解决方法来解决[Err] 1055的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MySQL异常:[Err] 1055Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nona...](https://download.csdn.net/download/weixin_38742656/13685329)[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* [[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated...](https://blog.csdn.net/miachen520/article/details/122390084)[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* [[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains](https://blog.csdn.net/qq_43514711/article/details/122041247)[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 ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值