Backup and restore a mysql database from a running Docker mysql container

NottDev
1 min readMar 5, 2019

--

It will help save your day.

# Backup

docker exec <CONTAINER> /usr/bin/mysqldump -u root — password=root <DATABASE> > backup.sql

For Windows using Powershell with a large database you should use

docker exec <CONTAINER> /usr/bin/mysqldump -u root --password=root  -r <DATABASE> | Set-Content backup.sql

It will preserve encoding from the Linux container.

# Restore

cat backup.sql | docker exec -i <CONTAINER> /usr/bin/mysql -u root  
--password=root <DATABASE>

--

--

NottDev
NottDev

Written by NottDev

Your only limit is your mind.

Responses (2)