问题描述
docker-compose:
docker-compose:
mysql:
image: mysql:5.7.16
container_name: f_mysql
volumes:
- ./db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: sheep
expose:
- '3306'
我使用 docker exec
输入此容器,
,我键入 echo $ MYSQL_ROOT_PASSWORD
,然后我得到 sheep
,
and I type echo $MYSQL_ROOT_PASSWORD
, then I got sheep
,
但是,当我输入'mysql -uroot'时,mysql root密码仍然是'',
but the mysql root password still is '',
',我登录mysql。
when I type 'mysql -uroot', I login mysql.
推荐答案
您需要修复docker-compose文件:
You need to fix your docker-compose file:
environment:
- MYSQL_ROOT_PASSWORD=sheep
以下是完成您想要的docker-compose:
The following is the full docker-compose that achieves what you want:
version: '2'
services:
mysql:
image: mysql:5.7.16
container_name: f_mysql
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=sheep
expose:
- '3306'
然后用一个 docker exec -it f-mysql / bin / bash
在容器内部 mysql -u root -p
中,使用羊作为密码,将是连接到mysql服务器的唯一方法。
Then with a docker exec -it f-mysql /bin/bash
and inside the container mysql -u root -p
, using sheep, as the password, will be the only way to connect to the mysql server.
这篇关于docker,MYSQL_ROOT_PASSWORD不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!