Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate a "create table" sql command based on an existing table in mysql

I have a mysql shell but for security reasons I cannot run the mysqldump command.

I have a table that I made a while ago with a lot of columns, and I want to generate a new "create table" command to create that table on a different database.

Is there some command I can run in the mysql shell to generate that?

Thanks.

like image 684
zak23 Avatar asked Aug 12 '09 02:08

zak23


2 Answers

This should work:


SHOW CREATE TABLE tbl_name

You should have SELECT privileges for the table.

like image 142
Freddy Avatar answered Sep 22 '22 05:09

Freddy


FYI, if your user has access to both databases on the same server, you can do this:

CREATE TABLE db2.tablename LIKE db1.tablename;
like image 40
gahooa Avatar answered Sep 24 '22 05:09

gahooa