Dumping MySQL database schema but not the data!

How many times have all you command line warriors out there been working with MySQL and backed up or moved a database with the trusty old mysqldump command? I know I use it all the time. But! What if you want to dump just the schema or structure of the database, and not all the data? Like going from DEV to TEST or PROD for example? You want to get the database setup, but you certainly don’t want all that data.

I can see you are interested! How hard is this you ask? Well my friends, this is yet another reason I love MySQL. You see, it’s as simple as -d. Yep, that’s it. Just add the -d to your mysqldump command and off you go, you get the structure of the database, but no data. Let me give you an example, if your normal dump command looks like this:

mysqldump mydatabase

simply do this:

mysqldump mydatabase -d

Yes, it’s that easy. You can still pipe it to a text file just like always:

mysqldump mydatabase -d > mydatabase.sql

There you go, get out there and export!

Tell me what you are thinking?