How to get query that would recreate sql table in PHPMyAdmin

Borut Flis picture Borut Flis · Aug 8, 2011 · Viewed 50.4k times · Source

I have table on MySQL server and would like to get the SQL that would re-create the table.

How do I get the query to recreate the SQL table?

Answer

J.J. picture J.J. · Aug 8, 2011

MySQL supports SHOW CREATE TABLE to return the SQL that was used to create a table.

From their docs:

mysql> SHOW CREATE TABLE t;
CREATE TABLE t (
  id INT(11) default NULL auto_increment,
  s char(60) default NULL,
  PRIMARY KEY (id)
) ENGINE=MyISAM

This can be useful if you have just a connection to the DB, versus a CLI on the server. If you have a CLI, use mysqldump like liamgriffiths recommends.