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

  • docker上新装的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

我们直接上永久解决方案

先查询容器运行状态:docker ps -a
在这里插入图片描述
然后进入容器:docker exec -it 容器名 /bin/bash
在这里插入图片描述
查看配置文件:cat /etc/mysql/my.cnf
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated_第1张图片
我这里是配置好的
接下来我们进入mysql命令行,查看其sql_mode配置:mysql -u root -p
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated_第2张图片
查看sql_modeshow variables like '%sql_mode';
这是出错情况下的:
在这里插入图片描述
我们的目的就是要将sql_mode字段去掉红圈部分
这是修改后的:
在这里插入图片描述

  • 我们先将上边的配置文件全部复制
  • 下边我们就是要在服务器本地新建一个文件,路径还可以是/etc/mysql/my.cnf,将内容复制进去,并在:[mysqld]下的末尾添加sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,所有内容如下:
# opyright (c) 2017, 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
secure-file-priv= NULL
# 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_ENGINE_SUBSTITUTION
  • 然后我们Esc——>:wq,如果权限不够,会提示加“!”,即:wq!,如果为只读,先set noreadonly,然后再:wq,保存成功并退出。然后我们退出命令行和容器,两个exit解决。
  • 接下来停止现在的容器,docker stop 容器名
  • 删除容器:docker rm 容器名
    接下来是重点,我们要将本地的配置文件映射为创建容器时使用的配置文件,即以本地配置文件启动容器
    这样以后也好修改,命令:docker run -d -p 3306:3306 -v /etc/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:latest,我的mysql版本是latest,我也没有映射data文件,想加的可以加。
  • 然后docker ps -a查看,没有问题后,我们再次进入新建的容器,接着进入mysql命令行,查看sql_mode,出现了上边的预期成功的sql_mode字段,就算成功。

你可能感兴趣的:(项目部署,mysql,linux,docker)