MySQL docker中的MySQL conf文件(MySQL conf file in MySQL docker)

编程入门 行业动态 更新时间:2024-10-27 01:20:48
MySQL docker中的MySQL conf文件(MySQL conf file in MySQL docker)

我在使用官方MySQL docker镜像创建的docker容器中运行MySQL 5.7.20。 MySQL conf文件需要安装在主机Ubuntu系统上。

目前MySQL docker容器是使用该命令启动的

sudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v /root/test/mysql/etc:/etc/mysql \ --name test-mysql \ mysql:5.7

但是/root/test/mysql/etc中没有配置文件...连接到docker容器的bash,发现/etc/mysql是空的!

conf文件位于何处? 在/etc/mysql/conf.d/和/etc/mysql/mysql.conf.d/不应该有一些吗?

I am running MySQL 5.7.20 in a docker container created using the official MySQL docker image. The MySQL conf file needs to be mounted on the host Ubuntu system.

Currently the MySQL docker container is started using the command

sudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v /root/test/mysql/etc:/etc/mysql \ --name test-mysql \ mysql:5.7

However there are no conf files in /root/test/mysql/etc... Connected to the docker container's bash and found that /etc/mysql is empty!

Where are the conf files located? Shouldnt there be some in /etc/mysql/conf.d/ and /etc/mysql/mysql.conf.d/?

最满意答案

如果您在不安装任何卷的情况下运行该命令:

$ docker run -it mysql ls /etc/mysql conf.d my.cnf my.cnf.fallback mysql.cnf mysql.conf.d

如果/root/test/mysql/etc作为空文件夹存在并将其挂载到/etc/mysql则/etc/mysql所有内容将被/root/test/mysql/etc “替换”。

您可以拥有一个空/root/test/mysql/etc文件夹并执行以下操作:

docker volume create --driver local \ --opt type=none \ --opt device=/root/test/mysql/etc \ --opt o=bind \ mysql_vol
sudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v mysql_vol:/etc/mysql \ --name test-mysql \ mysql:5.7

If you run the command without mounting any volumes:

$ docker run -it mysql ls /etc/mysql conf.d my.cnf my.cnf.fallback mysql.cnf mysql.conf.d

If /root/test/mysql/etc exists as an empty folder and you mount it onto /etc/mysql all the content of /etc/mysql will be "replaced" with those in /root/test/mysql/etc.

You can have an empty /root/test/mysql/etc folder and do the following:

docker volume create --driver local \ --opt type=none \ --opt device=/root/test/mysql/etc \ --opt o=bind \ mysql_vol
sudo docker run -d \ -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=test \ -v /root/test/mysql/var/lib:/var/lib/mysql \ -v mysql_vol:/etc/mysql \ --name test-mysql \ mysql:5.7

更多推荐

本文发布于:2023-08-05 17:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1436697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   docker   MySQL   file   conf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!