[英]Docker mysql change password
My docker-compose look like:我的 docker-compose 看起来像:
version: '3.4'
services:
mysql:
image: mysql:8.0
command:
- --default-authentication-plugin=mysql_native_password
volumes:
- ./mysql-data:/var/lib/mysql
env_file:
- .env
ports:
- 3306:3306
My.env file look like: My.env 文件如下所示:
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=db
MYSQL_USER=user
MYSQL_PASSWORD=user
Now if I change the password in .env
file, it does not change the password in the docker container after the restart.现在,如果我更改
.env
文件中的密码,它不会在重启后更改 docker 容器中的密码。 I suppose that happens because I have mapped volume from host to container and I think there are all settings saved.我想这是因为我已将卷从主机映射到容器,并且我认为所有设置都已保存。
My question is: How can I change the password for mysql, without modyfing or deleting mysql-data
folder?我的问题是:如何在不修改或删除
mysql-data
文件夹的情况下更改 mysql 的密码?
You can log in to the MySQL shell inside the container and then manually change the password following any standard MySQL guide.您可以在容器内登录 MySQL shell,然后按照任何标准 MySQL 指南手动更改密码。
To log in to the container, execute docker exec -it <container-id> mysql -u root -p
and provide the root password when prompted.要登录容器,请执行
docker exec -it <container-id> mysql -u root -p
并在提示时提供 root 密码。 After logging in, you can follow this guide to change the password: How to reset the root password in MySQL 8.0.11?登录后,您可以按照以下指南更改密码: 如何在 MySQL 8.0.11 中重置 root 密码?
To log in to the container shell (not MySQL shell), execute docker exec -it <container-id> bash
. To log in to the container shell (not MySQL shell), execute
docker exec -it <container-id> bash
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.