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

Nirav Shah is the Director of Eternal Web Pvt Ltd, an AWS Advanced Consulting Partner and certified Odoo Partner based in the UK. With over a decade of experience in cloud computing, digital transformation, and ERP implementation, Nirav helps enterprises adopt the right technology to solve complex business challenges. He specialises in AWS infrastructure, Odoo ERP, and web development solutions for businesses across the UK and beyond.
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.