# 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 | |
This comment has been minimized.
This comment has been minimized.
Thanks so much! :) |
This comment has been minimized.
This comment has been minimized.
This is really helpful, Thanks a million |
This comment has been minimized.
This comment has been minimized.
Awesome, thanks! |
This comment has been minimized.
This comment has been minimized.
For Windows using Powershell with a large database you should use # Backup It will preserve encoding from the Linux container. |
This comment has been minimized.
This comment has been minimized.
Thank you very much! |
This comment has been minimized.
This comment has been minimized.
thanks a lot :) |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Thank you very much :) |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
Thanks a lot :) |
This comment has been minimized.
This comment has been minimized.
Thanks a lot |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks! Official mysql image readme shows even more convenient way to do this if you use
|
This comment has been minimized.
This comment has been minimized.
Hi All, Hope all are doing great... I would like to know, how to restore MS SQL database from my host machine ( Docker engine running on this machine) to WINDOWS SQL container. Backup file exists in host machine C drive. Can anyone help on this? Please.... Thanks in Advance |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
So easy. Thanks! <3 |
This comment has been minimized.
This comment has been minimized.
You could also create a function in your
|
This comment has been minimized.
This comment has been minimized.
tks from China. useful to me~ |
This comment has been minimized.
This comment has been minimized.
Hehe keep on coming back to this gist! Thank you! |
This comment has been minimized.
This comment has been minimized.
Thanks you. |
This comment has been minimized.
This comment has been minimized.
where the dump is placing? |
This comment has been minimized.
This comment has been minimized.
Commenting my thanks after landing here from Google what feels like 10,000 times. Thanks! |
This comment has been minimized.
This comment has been minimized.
thanks |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
Awome.. Thanks |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Nice! |
This comment has been minimized.
This comment has been minimized.
Awesome, thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks very much! |
This comment has been minimized.
This comment has been minimized.
I use the following: |
This comment has been minimized.
This comment has been minimized.
@spalladino Thanks allot Mr. |
This comment has been minimized.
This comment has been minimized.
sapeee |
This comment has been minimized.
This comment has been minimized.
Please check my new solution. Special docker image that fast connect to any project for backup mysql database https://github.com/vmpartner/mysql-buckup |
This comment has been minimized.
This comment has been minimized.
This saved me a LOT of time! |
This comment has been minimized.
This comment has been minimized.
Awesome! Didn't think to make it this way with the pipe <3 |
This comment has been minimized.
This comment has been minimized.
Awesome ! Exactly what i was looking for :-) |
This comment has been minimized.
This comment has been minimized.
thanks <3 |
This comment has been minimized.
This comment has been minimized.
thanks a lot I love you |
This comment has been minimized.
This comment has been minimized.
Any solution here that doesn't require putting the password in the command? It will be available in the history |
This comment has been minimized.
This comment has been minimized.
You just saved me time! Thanks! |
This comment has been minimized.
This comment has been minimized.
Super!!! It's works pretty nice!! |
This comment has been minimized.
This comment has been minimized.
Thanks, this comes to be very useful :) |
This comment has been minimized.
This comment has been minimized.
That my solution when container is running
|
This comment has been minimized.
This comment has been minimized.
just what I needed, thanks a lot |
This comment has been minimized.
This comment has been minimized.
Thanks a lot man! |
This comment has been minimized.
This comment has been minimized.
thanks! |
This comment has been minimized.
This comment has been minimized.
I get "mysqldump: [Warning] Using a password on the command line interface can be insecure." and no backup is created |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
thanks a lot!! |
This comment has been minimized.
This comment has been minimized.
Alternative pipe syntax for restore action:
Note that pipe "points" in opposite direction, and there is no longer a need for 'cat' as shell will use file as stdin for docker exec with above syntax. |
This comment has been minimized.
This comment has been minimized.
Saved me too today, thanks! :) |
This comment has been minimized.
This comment has been minimized.
Thanks a lot |
This comment has been minimized.
This comment has been minimized.
Saved me too today, thanks! |
This comment has been minimized.
This comment has been minimized.
it does not works with an scheduled job :) |
This comment has been minimized.
This comment has been minimized.
Greate!!! |
This comment has been minimized.
This comment has been minimized.
Thanks. |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
You rock, thanks a ton! |
This comment has been minimized.
This comment has been minimized.
To spin up a one-time container, and also avoid polluting the output with
I like putting this in projects (via If you use the same image tag as your other container(s) (e.g.,
|
This comment has been minimized.
This comment has been minimized.
Gracias |
This comment has been minimized.
This comment has been minimized.
спасибо, чувак.! |
This comment has been minimized.
This comment has been minimized.
docker-compose exec CONTAINER mysql -ppass db_name -e "SOURCE initial-dump.sql" |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
You shall pass, thanks! |
This comment has been minimized.
This comment has been minimized.
great |
This comment has been minimized.
This comment has been minimized.
After running it shows: mysql: [Warning] Using a password on the command line interface can be insecure |
This comment has been minimized.
This comment has been minimized.
thank so much :) |
This comment has been minimized.
This comment has been minimized.
Thank you ! |
This comment has been minimized.
This comment has been minimized.
Thanks ;) |
This comment has been minimized.
This comment has been minimized.
Does anyone know, how to run this command in cron? |
This comment has been minimized.
This comment has been minimized.
use this code for cron job
|
This comment has been minimized.
This comment has been minimized.
Thankyou! Very helpfull :-) |
This comment has been minimized.
This comment has been minimized.
Super. Works well! |
This comment has been minimized.
This comment has been minimized.
Same, but with compression:# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE | gzip > `date +%Y-%m-%d-%T%z`-NAME.sql.gz` # Restore
zcat 2018-11-14-backup.sql.gz | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE |
This comment has been minimized.
This comment has been minimized.
using these commands all emojis in the database was broken for me. I needed to add the
|
This comment has been minimized.
This comment has been minimized.
thanks for sharing, very useful |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thank you a lot! Very useful. |
This comment has been minimized.
This comment has been minimized.
Awesome, thanks! |
This comment has been minimized.
This comment has been minimized.
Just in case anyone had an issue where it just didn't seem like the backup.sql file was being written anywhere here's what I used:
This worked for me the same exact way. Dunno why Want to add: I personally used the extra argument By the way, if you have a tiny DB like me you might consider just using |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
Just to fix.
or will backup inside the container. |
This comment has been minimized.
This comment has been minimized.
Backup and compress using $MYSQL_ROOT_PASSWORD env variableThis solution backups all databases, compress output file using gzip and more over you don't need to pass root password for it:
https://gist.github.com/saniaky/30985d144374b09bf5118dad52d721fa |
This comment has been minimized.
This comment has been minimized.
awesome thank you |
This comment has been minimized.
This comment has been minimized.
god |
This comment has been minimized.
This comment has been minimized.
Three years has past since this gist was published and it still helps people. Thanks) |
This comment has been minimized.
This comment has been minimized.
Thank you |
This comment has been minimized.
This comment has been minimized.
Thank you |
This comment has been minimized.
This comment has been minimized.
Awesome Thanks! |
This comment has been minimized.
This comment has been minimized.
Just found your comment! Life saver! |
This comment has been minimized.
This comment has been minimized.
Thank-you |
This comment has been minimized.
This comment has been minimized.
Thanks man :) |
This comment has been minimized.
This comment has been minimized.
Excellent thank you man!! |
This comment has been minimized.
This comment has been minimized.
Thanks man, very helpful |
This comment has been minimized.
This comment has been minimized.
You saved my day! Tank you |
This comment has been minimized.
This comment has been minimized.
many thanks! |
This comment has been minimized.
This comment has been minimized.
Great!!! Thanks |
This comment has been minimized.
This comment has been minimized.
Thank you so much!! |
This comment has been minimized.
This comment has been minimized.
Many thanx! |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Thanks, I was in a black hole for quite a few hours, and your code saved me! |
This comment has been minimized.
This comment has been minimized.
think i've been pulley's into a black hole now! On MacOS.
I can run mysqldump from normal terminal if that means anything? backup.sql : docker-compose:
|
This comment has been minimized.
This comment has been minimized.
for restore one table preparation step
|
This comment has been minimized.
This comment has been minimized.
Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
Thanks. It worked. |
This comment has been minimized.
This comment has been minimized.
Thanks so much! |
This comment has been minimized.
This comment has been minimized.
Using env variables set on
|
This comment has been minimized.
This comment has been minimized.
Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
thanks a bunch |
This comment has been minimized.
This comment has been minimized.
Thanks a lot man! |
This comment has been minimized.
This comment has been minimized.
but how to run this using docker-compose ? |
This comment has been minimized.
This comment has been minimized.
Another thank you. |
This comment has been minimized.
This comment has been minimized.
About mysql "[Warning] Using a password on the command line interface can be insecure"
|
This comment has been minimized.
This comment has been minimized.
Woow Great! Thank you very much! |
This comment has been minimized.
This comment has been minimized.
nice |
This comment has been minimized.
This comment has been minimized.
Thanks, very useful! |
This comment has been minimized.
This comment has been minimized.
Thanks! It is exactly what I was looking for |
This comment has been minimized.
This comment has been minimized.
This saved my butt today. Thanks. |
This comment has been minimized.
This comment has been minimized.
In case you needed to hear it again - nice work. Works perfik. |
This comment has been minimized.
This comment has been minimized.
That method of import has made my day. Been looking for a command that works to finish off a script for weeks |
This comment has been minimized.
This comment has been minimized.
Awesome! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
:O works perfectly... |
This comment has been minimized.
This comment has been minimized.
Thanks a lot, you made my day |
This comment has been minimized.
This comment has been minimized.
100th thank you. This results always shows up when I google this question. |
This comment has been minimized.
This comment has been minimized.
If you are using this command via docker-compose you have to detach the tty via -T switch like this: |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
Thank You! |
This comment has been minimized.
This comment has been minimized.
Thanks.. This helped!! |
This comment has been minimized.
This comment has been minimized.
Thanks a lot bro :D |
This comment has been minimized.
This comment has been minimized.
works fine, thanks! |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
YEEEEESSS! Thank you! |
This comment has been minimized.
This comment has been minimized.
Thanks a lot +1 |
This comment has been minimized.
This comment has been minimized.
If you have Unicode characters in your db, to avoid problem with encoding use this: #Backup |
This comment has been minimized.
This comment has been minimized.
OMG So simple but so helpful!! Thank you! |
This comment has been minimized.
This comment has been minimized.
thanks thats really helpful |
This comment has been minimized.
This comment has been minimized.
Excellent info, thanks everyone! |
This comment has been minimized.
This comment has been minimized.
Thanks. |
This comment has been minimized.
This comment has been minimized.
Thanks, really helpful! |
This comment has been minimized.
This comment has been minimized.
Works well, |
This comment has been minimized.
This comment has been minimized.
This requires a local The original |
This comment has been minimized.
This comment has been minimized.
So simple, so amazing! Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
works, thanks a lot! |
This comment has been minimized.
This comment has been minimized.
Backupdocker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql Restoredocker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE < backup.sql |
This comment has been minimized.
This comment has been minimized.
Thank you!! |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
I found this article a bit helpful - https://medium.com/@ricardolsmendes/mysql-mariadb-with-scheduled-backup-jobs-running-in-docker-1956e9892e78 Sharing this, because most of syntax examples of backup are almost the same. |
This comment has been minimized.
This comment has been minimized.
Thank you very much! |
This comment has been minimized.
This comment has been minimized.
thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks @vineetkumar03! |
This comment has been minimized.
This comment has been minimized.
thanks! |
This comment has been minimized.
This comment has been minimized.
on a side note those who are getting ERROR 1064 (42000) error |
This comment has been minimized.
This comment has been minimized.
Thanks!, really helpful |
This comment has been minimized.
This comment has been minimized.
Thanks! Bro. it's really helped me |
This comment has been minimized.
This comment has been minimized.
This is great! |
This comment has been minimized.
This comment has been minimized.
We are using this open-source container which autoamatically uploads to cheap jucy |
This comment has been minimized.
This comment has been minimized.
Hey guys, all of those commands work just fine when inserting up to 3-5Gig database. I even copy my DB into MySQL container, SET autocommit=0; SOURCE big_database_15GB.sql; COMMIT; And suddenly my container times out and it's broken. |
This comment has been minimized.
This comment has been minimized.
Great!!!! |
This comment has been minimized.
This comment has been minimized.
Thanks man. God bless you and @vineetkumar03 @colm-anseo |
This comment has been minimized.
This comment has been minimized.
Refer these steps Restart container |
This comment has been minimized.
This comment has been minimized.
this saved me many hours. thanks! |
This comment has been minimized.
this really saved my day, thanks