How to dump mysql table structure without data with a SQL query?

DatabaseMysql

Database Problem Overview


I need to export a mysql table, but it has like 5gb of entries, so I only want the structure. I am trying to do it from a simple php doing a sql query, how can I do that?

Database Solutions


Solution 1 - Database

You can use SHOW CREATE TABLE for this.

> Shows the CREATE TABLE statement that > creates the given table. The statement > requires the SELECT privilege for the > table. As of MySQL 5.0.1, this > statement also works with views.

E.g.:

SHOW CREATE TABLE MyTablename

Solution 2 - Database

I'm not a MySQL expert by any means but the following site suggests using the -d or --no-data option of mysqldump:

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

It worked for me.

Solution 3 - Database

if u have "MySQL Workbench" v6.0

  1. click on any table of the database.

  2. Right-click and select "Tables Maintenance"

  3. Under "Tables" tab, highlight the tables u want to export, right-click and select "Send to SQL Editor">"Create Schema"

Solution 4 - Database

It is already answered in the link below:
https://stackoverflow.com/questions/6175473/mysql-export-schema-without-data

Use the command below to take the structure or schema dump.

mysqldump -u root -p --no-data dbname > schema.sql

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHuransView Question on Stackoverflow
Solution 1 - DatabaseD'Arcy RittichView Answer on Stackoverflow
Solution 2 - Databasemp31415View Answer on Stackoverflow
Solution 3 - Databasegan garyView Answer on Stackoverflow
Solution 4 - DatabasePramatha VView Answer on Stackoverflow