How to Export and Import a Mysql Database Running on Docker

This series of commands serve as a guide in migrating a MySQL database from one docker instance to another.

1. Computer where source MySQL database server is running on docker.

1.1 Get the container id of the docker instance where the MySQL source server is running.

// copy the "CONTAINER ID"
>docker ps

1.2 Export the MySQL database.

// Change the "CONTAINER ID", PASSWORD, and DATABASE values
// Note that it will create a db-dump.sql file in the folder where the command is run
>docker exec "CONTAINER ID" /usr/bin/mysqldump -u root --password=PASSWORD DATABASE > db-dump.sql

2. Computer where target MySQL database server is running on docker.

2.1 Get the container id of the docker instance where the MySQL target server is running.

// copy the "CONTAINER ID"
>docker ps

2.2 Import the MySQL database.

// Change the "CONTAINER ID", PASSWORD, and DATABASE values
// Note that it will it need a db-dump.sql file in the folder where the command will be run run
cat db-dump.sql | docker exec -i "CONTAINER ID" /usr/bin/mysql -u root --password=PASSWORD DATABASE

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post
NERV Open Source
Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.