How to dump MySQL database structure

Dump MySQL database structure

It is sometimes necessary to dump the database table structure only , it means do not dump database table content and only dump the CREATE TABLE statement for the database table . Already we seen about how to dump the MySQL database using mysqldump command line tool . Now we will see how to dump the MySQL database table structure only .

How to login mysql in command line

Syntax :

mysqldump -u <DB-USER> -p <DB-NAME> -d > dumpname.sql

Example:

#  mysqldump -d -u root -p  my_db  >  my_db_structure.sql
Enter password: < Enter your mysql password here  >

Here -d is the command line flag of mysqldump to get the dump of MySQL database table structure.  Alternatively we can use –no-data instead of -d flag ..

#  mysqldump --no-data -u root -p  my_db  >  my_db_structure.sql
Enter password: < Enter your mysql password here  >

You dump particular table structure in a database with no data

Syntax:

mysqldump -d -u  <DB-USER>  -p   <DB-NAME>  <TABLE-NAME>  > dumpname.sql

Example:

#  mysqldump -d -u root -p  my_db my_db_table >  my_db_structure.sql
Enter password: < Enter your mysql password here  >

Alternatively

#  mysqldump --no-data -u root -p  my_db my_db_table >  my_db_structure.sql
Enter password: < Enter your mysql password here  >

Here my_db_table is mentioned for table name .




Leave a Reply

Your email address will not be published. Required fields are marked *