Last active
September 14, 2023 19:27
-
-
Save duiliogp/3d224123e53622e483eec9c820f667b0 to your computer and use it in GitHub Desktop.
MySQL Export Database
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
# Backup | |
docker exec CONTAINER mysqldump --routines --triggers --user root --password=root DATABASE > ./backup.sql | |
# Restore | |
docker exec -i CONTAINER mysql --user root --password=root DATABASE < ./backup.sql |
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
# MySQL Export Database | |
##################### | |
### Variables | |
##################### | |
SQL_FILENAME="" | |
EXPORT_HOST="" | |
EXPORT_USER="" | |
EXPORT_PASSWORD="" | |
EXPORT_PORT="" | |
EXPORT_DBNAME="" | |
##################### | |
### Export | |
##################### | |
mysqldump -alv \ | |
--default-character-set=utf8 \ | |
--lock-tables=false \ | |
--routines \ | |
--triggers \ | |
--single-transaction=TRUE \ | |
--host=$EXPORT_HOST \ | |
--port=$EXPORT_PORT \ | |
--user=$EXPORT_USER \ | |
--password=$EXPORT_PASSWORD $EXPORT_DBNAME > /home/$USER/Desktop/$SQL_FILENAME.sql | |
# more options | |
# --opt --where="1 limit 5000" \ | |
# --ignore-table-data=$DB_NAME.table_name1 \ | |
# --ignore-table-data=$DB_NAME.table_name2 \ |
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
##################### | |
### Variables | |
##################### | |
SQL_FILENAME="" | |
IMPORT_HOST="" | |
IMPORT_USER="" | |
IMPORT_PASSWORD="" | |
IMPORT_PORT="" | |
IMPORT_DBNAME="" | |
##################### | |
### Import | |
##################### | |
echo 'CREATE DATABASE.' | |
mysql --protocol="tcp" --host=$IMPORT_HOST --user=$IMPORT_USER --password=$IMPORT_PASSWORD --port=$IMPORT_PORT --execute="CREATE DATABASE $IMPORT_DBNAME" | |
echo 'IMPORT DATABASE.' | |
mysql --protocol="tcp" \ | |
--host=$IMPORT_HOST \ | |
--user=$IMPORT_USER \ | |
--password=$IMPORT_PASSWORD \ | |
--port=$IMPORT_PORT \ | |
--default-character-set=utf8 \ | |
--comments \ | |
--database=$IMPORT_DBNAME < "/home/$USER/Desktop/$SQL_FILENAME.sql" | |
### Show Databases | |
mysql --protocol="tcp" --host=$IMPORT_HOST --user=$IMPORT_USER --password=$IMPORT_PASSWORD --port=$IMPORT_PORT --execute='SHOW DATABASES' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment