bash 如何从mysql docker容器重启mysql服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52993172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to restart mysql service from mysql docker container
提问by Serega Belous
I'm using tommylau/mysql docker image which provides mysql installed.
我正在使用提供 mysql 安装的 tommylau/mysql docker 映像。
But after all i can't find how to restart mysql service inside running container (there is no mysql service or /etc/init.d/mysqld)
但毕竟我找不到如何在正在运行的容器内重新启动 mysql 服务(没有 mysql 服务或 /etc/init.d/mysqld)
Any idea how to find how to restart mysql?
知道如何找到如何重新启动 mysql 吗?
回答by mtt_g
If you log into the container and attempt to restart the service it will essentially kill the container at the point in which the mysql process stops and therefore it'll never start (as the container has exited).
如果您登录容器并尝试重新启动服务,它实际上会在 mysql 进程停止时终止容器,因此它将永远不会启动(因为容器已退出)。
The best way is to simply restart the container using the following command:
最好的方法是使用以下命令简单地重新启动容器:
docker restart [ContainerID]
回答by Zgpeace
when you enter the MySQL Container, use the command,
当你进入 MySQL Container 时,使用命令,
docker exec -it $(Container Id or Name) bash
docker exec -it $(Container Id or Name) bash
you can modify the file vim /etc/mysq/my.cnf
for example, open the slow query toggle, below [mysqld]
,
您可以修改文件vim /etc/mysq/my.cnf
,例如,打开下面的慢查询开关[mysqld]
,
[mysqld]
slow_query_log = ON
long_query_time = 1
save the file with :wq
.
then exit
the MySQL Container.
Then Restart the MySQL Container.
保存文件:wq
。
然后exit
是 MySQL 容器。
然后重新启动 MySQL 容器。
docker restart $(Container Id or Name)
enter the Container
进入容器
docker exec -it $(Container Id or Name) bash
login MySQL with user root
以 root 用户登录 MySQL
mysql -u root -p
query 'long_query_time'
, the value change to 1
查询'long_query_time'
,值更改为1
mysql> show variables like 'long_query_time';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 1.000000 |
+-----------------+----------+
1 row in set (0.00 sec)
回答by Rutger Vk
An easy was going into your container
很容易进入你的容器
docker exec -it [containername/id] bin/bash
after entering the container restart mysql
进入容器后重启mysql
restart mysql
or just restart your container like in the answer above
或者像上面的答案一样重启你的容器