前言
docker内启动MySQL报错
说是配置文件有问题,排查着看看吧,也告诉了行数,对应查看就行,有的是第一行,从其他博客来看是少了[mysqld]
参考文章
如何解决mysql配置文件错误导致在docker中无法启动的问题 docker容器Mysql停止运行了如何启动
mysql提示Found option without preceding group in config file 用处不大参考
解决
查看停止的容器
查看容器配置
只看关键数据UpperDir
这是他的安装路径
实际配置文件则在下边
查看配置文件
[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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
根据报错可以看到第25行是bind-address = 0.0.0.0
这个是授权远程访问
,看来这段配置有问题,索性直接给注释掉,复制文件出去回来太麻烦,使用个简单命令替换
替换配置(忽略 这步没用 写在这提个醒)
用法
# 指定行替换 不加数字是全局替换
[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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
可以看到第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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
重启
启动成功
[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 ~]#
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.