Skip to content

Instantly share code, notes, and snippets.

@dreamlu
Forked from spalladino/mysql-docker.sh
Created May 31, 2019 01:40
Show Gist options
  • Save dreamlu/1e5591d72570a5dd2cf1da4bd84ff8e9 to your computer and use it in GitHub Desktop.
Save dreamlu/1e5591d72570a5dd2cf1da4bd84ff8e9 to your computer and use it in GitHub Desktop.
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@dreamlu
Copy link
Author

dreamlu commented Mar 8, 2021

导出所有数据库:
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root --all-databases > backup.sql
ps: 导入一定要是同一版本数据库,否则重启后可能会有bug(导出的库包含了系统数据库)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment