/etc/mysql/my.cnf更改后,MySQL容器崩溃,如何重新编辑? [英] MySQL container crash after /etc/mysql/my.cnf change, how to edit back?

查看:123
本文介绍了/etc/mysql/my.cnf更改后,MySQL容器崩溃,如何重新编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更改了一些mysql配置设置,并设置了一些错误,现在Docker容器不断重新启动,我找不到要在主机文件系统中进行编辑的 my.cnf 文件.我尝试了aufs/diff文件夹,但到目前为止找不到它.还尝试过:

I changed some mysql config settings and set something wrong, now Docker container keeps restarting and I cannot find the my.cnf file to edit in host filesystem. I have tried aufs/diff folders but so far unable to find it. Also tried:

find / -name my.cnf -exec nano {} \;

但是它不会显示我更改过的文件.我试图更改 config.v2.json 而不是 mysqld 来启动/bin/bash ,并重新启动了docker,但它却启动了 mysqld (由于主管或其他原因?)使用官方的mysql容器映像.

But it does not bring up the file I changed. And I tried to change config.v2.json to start /bin/bash instead of mysqld and restarted docker, but yet it started mysqld (due supervisor or something?) using official mysql container image.

推荐答案

我看到了两种可能的解决方案:

I am seeing two possible solutions for your problem:

绕过MySQL映像的ENTRYPOINT

通过运行 docker images 查找图像名称,然后运行:

Find your image name by running docker images then run:

docker run -it --entrypoint="/bin/sh" OPTIONS image

这应该带您进入容器内的bash,然后可以在其中执行要查找 my.cnf 文件的所有命令.尽管我不知道是否可以从那里编辑文件,但是保存并尝试再次运行它是可行的.我没有尝试.

That should take you to the bash inside the container and from there you can execute all the commands you want to find your my.cnf file. Although I don't know if editing the file from there, save it and try to run it again will works. I didn't tried.

删除旧图像,并使用正确的方式编辑 my.cnf 文件

Delete the old image and use the proper way to edit the my.cnf file

运行以下命令查找映像名称: docker images ,然后运行 docker rmi< image_name>

Find your image name by running: docker images and then delete it by running docker rmi <image_name>

MySQL Dockerhub 上检查文档以获取默认的MySQL映像我引用:

Check the docs for the default MySQL images at MySQL Dockerhub is pretty straight on this and I quote:

使用自定义MySQL配置文件MySQL启动

Using a custom MySQL configuration file The MySQL startup

配置,并且该文件又包括在/etc/mysql/conf.d中找到的所有文件以.cnf结尾的目录.此目录中文件的设置将增加和/或覆盖/etc/mysql/my.cnf中的设置.如果你想使用自定义的MySQL配置,您可以创建替代方案配置文件放在主机上的目录中,然后挂载该目录位置为mysql中的/etc/mysql/conf.d容器.

configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.

如果/my/custom/config-file.cnf是自定义文件的路径和名称配置文件,您可以像这样启动mysql容器(注意在此仅使用自定义配置文件的目录路径命令):

If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):

$ docker run --name some-mysql -v/my/custom:/etc/mysql/conf.d -eMYSQL_ROOT_PASSWORD =我的秘密-pw -d mysql:tag

这将开始一个新的容器some-mysql,其中MySQL实例使用组合/etc/mysql/my.cnf中的启动设置和/etc/mysql/conf.d/config-file.cnf,带有后者的设置优先.

This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.

从那时起,如果您在主机上创建 my.cnf 文件,那么您将再也不会遇到此问题,因为您可以根据需要编辑该文件多次.

From that point and if you create the my.cnf file on your host then you'll never run into this problem again since you can edit the file as many times as you want.

这篇关于/etc/mysql/my.cnf更改后,MySQL容器崩溃,如何重新编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆