MySQL - How to dump a MySQL database and export schema only, no data?
To export a MySQL database to a dump file without any data, you can use —no-data
in mysqldump:
mysqldump -u <user_name> -h <server> -p --no-data <db_name> > schema.sql
Or you can use -d
to empty all the tables before dumping:
mysqldump -u <user_name> -h <server> -p -d <db_name> > schema.sql
If you want to extract a specific table with schema only:
mysqldump -u <user_name> -h <server> -p --no-data <db_name> <table_name> > schema.sql
Need a good GUI Tool for MySQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.