Created
October 12, 2021 17:59
-
-
Save eastside/8648be4c7f88e8b7c6bbaaa9cd47e60e to your computer and use it in GitHub Desktop.
Copy a MySQL database using native MySQL tools without a dumpfile
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
# Pipes data from one MySQL database into another. | |
# Tested with AWS Aurora MySQL (using a 5.7-compatible version of MySQL) to AWS RDS MySQL 8.0. | |
# Probably only suitable for small (<1 TB) databases. | |
# It takes a long time, and if it breaks halfway through you just have to start over from scratch. | |
# Probably not suitable for production without a bunch more work. | |
export $SOURCE_USER= | |
export $SOURCE_HOST= | |
export $SOURCE_PW= | |
# Needs to be a comma-separated list of tables, i.e., user,sale,item | |
export $TABLE_NAMES_COMMA_SEP= | |
export $DEST_USER= | |
export $DEST_HOST= | |
export $DEST_PW= | |
export $DB_NAME= | |
# MySQL pump (notice the "p") has nicer output than MySQLdump | |
mysqlpump \ | |
-u $SOURCE_USER \ | |
-h $SOURCE_HOST \ | |
--add-drop-table \ | |
--password=$SOURCE_PW \ | |
--set-gtid-purged=OFF \ | |
--watch-progress \ | |
--default-parallelism=4 \ | |
--include-databases $DB_NAME \ | |
--include-tables=$TABLE_NAMES_COMMA_SEP \ | |
| sed "s/SET @@SESSION.SQL_LOG_BIN= 0;//" \ | |
| sed "s/SET @@GLOBAL\.GTID_PURGED=\/\*!80000 '+'\*\/ '';//" \ | |
| mysql \ | |
-u $DEST_USER \ | |
-h $DEST_HOST \ | |
--password=$DEST_PW $DB_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment