How to retrieve schema from a MySQL database using mysqldump

This article defines a method for extracting schema from a particular MySQL database, without dumping the data from the tables.

This procedure can be helpful in cases of migration where you want schema but not the data of target database.

For example, checking if Application DB for version X can be migrated to Application DB version Y.

Dump Table Structure

mysqldump -h localhost -u root -proot@123 -P3306 --single-transaction --skip-comments --no-data --skip-routines --skip-triggers --skip-events --add-drop-database --set-gtid-purged=OFF --hex-blob --databases emsent_dplicense | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | sed -e 's/DEFINER[ ]*=[ ]*[^*]*PROCEDURE/PROCEDURE/' | sed -e 's/DEFINER[ ]*=[ ]*[^*]*FUNCTION/FUNCTION/' > ems52_schema_tables.sql 

Dump Routines, Triggers and Events Structure

mysqldump -h localhost -u root -proot@123 -P3306 --single-transaction --skip-comments --no-create-db --no-data --no-create-info --routines --triggers --events --set-gtid-purged=OFF --hex-blob --databases emsent_dplicense | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | sed -e 's/DEFINER[ ]*=[ ]*[^*]*PROCEDURE/PROCEDURE/' | sed -e 's/DEFINER[ ]*=[ ]*[^*]*FUNCTION/FUNCTION/' > ems52_schema_routines.sql

Reload both the files into target database and you are ready.

You can rename the dump files as per your choice, just an advice to keep the names descriptive.

Comments

Back To Top

Popular posts from this blog

error 18 at 0 depth lookup: self signed certificate

How to check fragmentation in MySQL tables

How to Drop or Remove or Decommission a Database in Oracle