Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evasilev/dff34cde11495342bfb30199ca9e6823 to your computer and use it in GitHub Desktop.
Save evasilev/dff34cde11495342bfb30199ca9e6823 to your computer and use it in GitHub Desktop.
Easily compare with diff, mysqldump two DB tables only (no data)
# Easily compare with diff, mysqldump two DB table schemas ignoring /* SET Comments etc... */ with grep
# Used originaly to locate missing custom tables from Magento 1.x to Magento 2.x after data migration
# dump both databases with as little details as possible (DONT run these in production without table locking disabled!)
# Use grep to remove /* SET ... */ like comments from dump and save to > dbX.sql
mysqldump --skip-set-charset --skip-triggers --skip-opt -K --skip-comments --skip-extended-insert -d --no-data -u root -p db1 | grep -v '^\/\*![0-9]\{5\}.*\/;$' > db1.sql;
mysqldump --skip-set-charset --skip-triggers --skip-opt -K --skip-comments --skip-extended-insert -d --no-data -u root -p db2 | grep -v '^\/\*![0-9]\{5\}.*\/;$' > db2.sql;
# compare both db dumps and grep for only CREATE TABLE lines
diff db1.sql db2.sql | grep -iP '^\<.CREATE.TABLE.\`.+\`'
# Example output of diff:
< CREATE TABLE `admin_assert` (
< CREATE TABLE `admin_role` (
< CREATE TABLE `admin_rule` (
< CREATE TABLE `api2_acl_attribute` (
< CREATE TABLE `api2_acl_role` (
< CREATE TABLE `api2_acl_rule` (
< CREATE TABLE `api2_acl_user` (
< CREATE TABLE `api_assert` (
< CREATE TABLE `api_role` (
< CREATE TABLE `api_rule` (
< CREATE TABLE `api_session` (
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment