Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

database

mysql

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?

like image 250
Hurans Avatar asked Nov 27 '10 23:11

Hurans


People also ask

How will you take the table and schema structure only by Mysqldump?

Use the --no-data switch with mysqldump to tell it not to dump the data, only the table structure. This will output the CREATE TABLE statement for the tables. To target specific tables, enter them after the database name.

Does Mysqldump include data?

Mysqldump is a command-line utility that is used to generate the logical backup of the MySQL database. It produces the SQL Statements that can be used to recreate the database objects and data. The command can also be used to generate the output in the XML, delimited text, or CSV format.


1 Answers

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 
like image 187
D'Arcy Rittich Avatar answered Sep 21 '22 18:09

D'Arcy Rittich