fbpx

Upgrade MySQL 5.7 to 8 on Docker

To upgrade MySQL from version 5.7 to version 8 on Docker, you can follow these steps:

  1. Stop the MySQL 5.7 container:
				
					docker stop mysql or <Name of container></Name>
				
			
  1. 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

				
			
  1. Remove the MySQL 5.7 container:
				
					docker rm mysql

				
			
  1. Pull the MySQL 8 Docker image:
				
					docker pull mysql:8

				
			
  1. 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=<password> -d mysql:8

docker exec mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < /path/to/all-databases.sql

				
			
  1. (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=<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.

Share:

Facebook
Twitter
Pinterest
LinkedIn

Social Media

Most Popular

Get The Latest Updates

Subscribe To Our Weekly Newsletter

No spam, notifications only about new products, updates.

Categories