LOGO

MySQL: Export Table Structure Only - How To

September 11, 2006
MySQL: Export Table Structure Only - How To

Backing Up Database Structure with mysqldump

This process details how to utilize the mysqldump utility to create a backup of only the database structure, mirroring the approach used for full database backups.

Command Syntax

The fundamental syntax for this operation is as follows:

mysqldump -d -h localhost -u root -pmypassword databasename > dumpfile.sql

This command directs mysqldump to generate a SQL file containing the database's schema.

Key Option: -d

The primary distinction between this structural backup and a complete database backup lies in the inclusion of the -d option.

Specifically, the -d switch instructs mysqldump to exclude the actual data from the output file.

Practical Example

Consider the following example demonstrating the command in action:

mysqldump -d -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql

In this instance, a file named dumpfile.sql will be created, containing only the structure of the database01 database.

The command connects to the MySQL server at localhost as the root user, utilizing the password 2Uad7as9.

This resulting SQL file can then be used to recreate the database structure on another server or for other administrative purposes.

#MySQL#table structure#schema#dump#export#database