To upgrade MySQL from version 5.7 to version 8 on Docker, you can follow these steps:
- Stop the MySQL 5.7 container:
docker stop mysql or
- Create a backup of your MySQL 5.7 data:
docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > all-databases.sql
- Remove the MySQL 5.7 container:
docker rm mysql
- Pull the MySQL 8 Docker image:
docker pull mysql:8
- Create a new MySQL 8 container and restore your data:
docker run --name mysql -v /path/to/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD= -d mysql:8
docker exec mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < /path/to/all-databases.sql
- (Optional) If you have custom configurations in your
my.cnf
file, you can mount the file as a volume when starting the MySQL 8 container:
docker run --name mysql -v /path/to/mysql/data:/var/lib/mysql -v /path/to/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD= -d mysql:8
That’s it! Your MySQL installation should now be upgraded to version 8.
I hope this helps. Let me know if you have any questions.