How to get Mysql table structure via mysql shell

Note: it maybe useful if you need to copy existing table srtucture somewhere.
To do that just type:

show create table table_name;

For example, let’s run this command for table ‘test’:

mysql> show create table test;

and there is our result:

mysql> show create table test1;
+-------+-------------------------------------+
| Table| Create Table                    |
+-------+-------------------------------------+
| test1 | CREATE TABLE `test1` (
  `f1` varchar(20) default NULL
) TYPE=MyISAM                           |
+-------+-------------------------------------+
1 row in set (0.00 sec)

Published by

Michael Stepanov

Site owner and admin :)

3 thoughts on “How to get Mysql table structure via mysql shell”

  1. But if the only thing that you need is the table’s structure and not the SQL statement to create it – the command DESCRIBE table seems much more convenient to me 8)

  2. Yes, you are right. But I’m talking about getting a table structure from one database to create the same table in the another database. Probably I didn’t write clearly this moment 🙂

Leave a Reply

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