mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 25!

前言

docker内启动MySQL报错

mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 25!

说是配置文件有问题,排查着看看吧,也告诉了行数,对应查看就行,有的是第一行,从其他博客来看是少了[mysqld]
参考文章
如何解决mysql配置文件错误导致在docker中无法启动的问题
docker容器Mysql停止运行了如何启动
mysql提示Found option without preceding group in config file 用处不大参考

解决

查看停止的容器

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS                     PORTS                                                  NAMES
95fee519e228        mysql:5.7                             "docker-entrypoint..."   20 months ago       Exited (1) 5 minutes ago                                                          c_mysql

查看容器配置

只看关键数据UpperDir 这是他的安装路径

[root@localhost ~]# docker inspect 95fee519e228
{
 {
                "UpperDir": "/var/lib/docker/overlay2/c286fdbf488e325a903fc68a0c1e13a1ef40c5c3d5012d6bcae7cc4d0ac11d1a/diff",
                "WorkDir": "/var/lib/docker/overlay2/c286fdbf488e325a903fc68a0c1e13a1ef40c5c3d5012d6bcae7cc4d0ac11d1a/work"
            }
        }

实际配置文件则在下边

/var/lib/docker/overlay2/c286fdbf488e325a903fc68a0c1e13a1ef40c5c3d5012d6bcae7cc4d0ac11d1a/diff/etc/mysql

在这里插入图片描述

查看配置文件

[root@localhost ~]# cat /var/lib/docker/overlay2/c286fdbf488e325a903fc68a0c1e13a1ef40c5c3d5012d6bcae7cc4d0ac11d1a/diff/etc/mysql/my.cnf
# Copyright (c) 2016, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# 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, version 2.0, 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/
bind-address = 0.0.0.0

根据报错可以看到第25行是bind-address = 0.0.0.0 这个是授权远程访问,看来这段配置有问题,索性直接给注释掉,复制文件出去回来太麻烦,使用个简单命令替换

替换配置(忽略 这步没用 写在这提个醒)

用法

 #指定行
 sed '3 s/old/new/' filename
 #全局
sed 's/old/new/g' filename
# 指定行替换 不加数字是全局替换
[root@localhost ~]#  sed '25 s/bind-address = 0.0.0.0/#bind-address = 0.0.0.0/'  /var/lib/docker/overlay2/c286fdbf488e325a903fc68a0c1e13a1ef40c5c3d5012d6bcae7cc4d0ac11d1a/diff/etc/mysql/my.cnf
# Copyright (c) 2016, 2021, Oracle and/or its affiliates.
#
# 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/
#bind-address = 0.0.0.0

可以看到第25行已经被替换注释,但是实际上因为文件只读原因,vi,sed 都无法修改

复制文件

#用法
sudo docker cp 容器ID:目标文件 LINUX外部路径
[root@localhost ~]# sudo docker cp 95fee519e228:/etc/mysql/my.cnf /etc/mysql/conf
# 外部修改好文件查看下没问题 复制进去 颠倒顺序即可 不加my.cnf文件名
[root@localhost ~]# sudo docker cp /etc/mysql/conf/my.cnf 95fee519e228:/etc/mysql/
#确保万一可以使用cat命令查看下复制好的文件是否正确
[root@localhost ~]# cat /var/lib/docker/overlay2/c286fdbf488e325a903fc68a0c1e13a1ef40c5c3d5012d6bcae7cc4d0ac11d1a/diff/etc/mysql/my.cnf
# Copyright (c) 2016, 2021, Oracle and/or its affiliates.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
#bind-address = 0.0.0.0

在这里插入图片描述

重启

启动成功

[root@localhost ~]# docker start c_mysql
c_mysql
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                                                  NAMES
6e094e785473        registry.aliyuncs.com/openspug/spug   "/entrypoint.sh"         3 months ago        Up 3 months         0.0.0.0:801->80/tcp                                    spug
f5a99eea5a33        redis:5.0                             "docker-entrypoint..."   15 months ago       Up 6 months         0.0.0.0:6379->6379/tcp                                 redis
a4a81ae45d8e        zookeeper:3.7.0                       "/docker-entrypoin..."   20 months ago       Up 6 months         2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp   zookeeper
95fee519e228        mysql:5.7                             "docker-entrypoint..."   20 months ago       Up 6 seconds        33060/tcp, 0.0.0.0:3307->3306/tcp                      c_mysql
[root@localhost ~]# 
  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值