Monday, June 18, 2012

Dumping the database structure for all tables with no data

Dumping the database structure for all tables with no data

Add the -d flag to signify that no data should be included in the output like so, where "mydatabase" is the name of the database to dump, and "someuser" is the login name used to connect to the database. The following command will dump the table structure for all tables in the specified MySQL database:

mysqldump -d -u someuser -p mydatabase
 
The -d flag says not to include data in the dump. Alternatively you can use --no-data instead if you find that easier to remember:

mysqldump --no-data -u someuser -p mydatabase
 
The -u flag indicates the username and the -p flag that a password will be supplied. After pressing you will be prompted for the password.

Alternatively, the password can be supplied on the command line, but there must be no space between the -p flag and the password. For example, if the password was "apples" do this:

mysqldump --no-data -u someuser -papples mydatabase