January 7, 2021 / Nirav Shah
This an interesting yet simple way to migrate databases between MySQL containers:
Step 1: Launch the first MySQL container.
$ docker container run --detach --env MYSQL_ALLOW_EMPTY_PASSWORD=True --volume mysqldb:/var/lib/mysql --publish 3306:3306 --name mysql-1 mysql $ docker container exec --interactive --tty mysql-1 /bin/bash # mysql -u root -p (Press enter on the "Enter password:" prompt) mysql> create database tobemigrated1; mysql> create database tobemigrated2; mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | tobemigrated1 | | tobemigrated2 | +--------------------+ 6 rows in set (0.00 sec)
Step 2: Stop the first MySQL container and Launch the second MySQL container.
$ docker container stop mysql-1 $ docker container run --detach --env MYSQL_ALLOW_EMPTY_PASSWORD=True --volume mysqldb:/var/lib/mysql --publish 3306:3306 --name mysql-2 mysql $ docker container exec --interactive --tty mysql-2 /bin/bash # mysql -u root -p (Press enter on the "Enter password:" prompt) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | tobemigrated1 | | tobemigrated2 | +--------------------+ 6 rows in set (0.00 sec)
Conclusion
As a Director of Eternal Web Private Ltd an AWS consulting partner company, Nirav is responsible for its operations. AWS, cloud-computing and digital transformation are some of his favorite topics to talk about. His key focus is to help enterprises adopt technology, to solve their business problem with the right cloud solutions.
Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.