Skip to content

Instantly share code, notes, and snippets.

@carlosspohr
Created September 11, 2014 14:00
Show Gist options
  • Select an option

  • Save carlosspohr/bce9392dbae0fd5c1815 to your computer and use it in GitHub Desktop.

Select an option

Save carlosspohr/bce9392dbae0fd5c1815 to your computer and use it in GitHub Desktop.
Helper bash script to dump all missing tables from an incomplete database compared with complete database. Very useful when you have an outdated database or working on migrations.
mysql -uroot -pyour-pass -e 'SELECT CONCAT(t1.TABLE_NAME, "") AS missing_tables FROM information_schema.TABLES t1 WHERE t1.table_schema = "complete_database" AND t1.TABLE_NAME NOT IN (SELECT t2.TABLE_NAME FROM information_schema.TABLES t2 WHERE t2.table_schema = "incomplete_database") ORDER BY t1.TABLE_NAME ASC' | grep -v missing_tables | xargs mysqldump --skip-add-drop-table -uroot -pyour-pass -d --routines complete_database > missing-tables.sql
@caarlos0
Copy link

oh my

@luizkowalski
Copy link

thanks god i'm not @carlosjrcabello

@carlosspohr
Copy link
Author

ouaehoueha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment