My docker-compose look like:
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:
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. 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?
You can log in to the MySQL shell inside the container and then manually change the password following any standard MySQL guide.
To log in to the container, execute docker exec -it <container-id> mysql -u root -p
and provide the root password when prompted. After logging in, you can follow this guide to change the password: How to reset the root password in MySQL 8.0.11?
To log in to the container shell (not MySQL shell), execute docker exec -it <container-id> bash
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.