Mysql: How to dump only the table schema

How to export the table schema from mysql?

Using mysqldump query, you can easily extract the table schema of your table. What you need is to add the -d parameter with your mysqldump command.

mysqldump -uUSERNAME -pPASSWORD DATABASE_NAME TABLE_NAME -d > TABLE_NAME.SQL

Here,
USERNAME = your mysql username;
PASSWORD = your mysql password;
DATABASE_NAME = your database name;
TABLE_NAME = the table you want to dump structure.

Usually mysqldump command used to dump all the table structure with the data. But if you add -d parameter, it will exclude all the data from the dumping, and only save the table structure.

Example:
mysqldump -uroot test test1 -d > table.sql

Output:
DROP TABLE IF EXISTS `test1`;
CREATE TABLE `test1` (
`name` varchar(255) default NULL,
`info` text
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Comments