Last active
December 4, 2021 17:26
-
-
Save SvS30/0a71fd7416c936414346842f16bb0616 to your computer and use it in GitHub Desktop.
commands to backup or restore a mysql instance in a docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I use the '$' symbol to indicate that they are variables, change those values. | |
# Backup | |
docker exec $name-container mysqldump -u $user --password=$pwd $database > $file-name.sql | |
# Restore | |
cat $file-name.sql | docker exec -i $name-container mysql -u $user --password=$pwd $database | |
# if you don't want to type your password by terminal, or are concerned about mysql warnings. | |
# You can do this: | |
# Step 1: enter your container: | |
docker exec -it $name-container bash | |
# Step 2: use mysql editor | |
mysql_config_editor set --login-path=local --host=localhost --user=$username --password | |
# this will create a file in your container, with your credentials and use it for login. | |
# Now to log into a restore application: | |
# if your .sql doesn't create the database, it should specify it in $database. | |
cat $file-name.sql | docker exec -i $name-container mysql --login-path=local $database | |
# or to make a backup: | |
docker exec $name-container mysqldump --login-path=local $database > $file-name.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment