Skip to content

Instantly share code, notes, and snippets.

@parhamr
Last active December 25, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parhamr/6912365 to your computer and use it in GitHub Desktop.
Save parhamr/6912365 to your computer and use it in GitHub Desktop.
Fast, safe (excepting schema changes), and ugly data transfer between MySQL databases
  1. Source host: mysqldump --skip-opt -e -q --compact --single-transaction -n -t --set-charset [$database_name] [$tables]
  2. Move the dump to destination host (scp)
  3. lock destination $tables
  4. truncate destination $tables
  5. `SET SESSION sql_mode='ALLOW_INVALID_DATES'; SET SESSION foreign_key_checks=0; SET SESSION unique_checks=0; SET SESSION autocommit=0;
  6. Load dump as SQL source
  7. commit transaction
  8. unlock destination $tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment