How to copy table structure from one database to another?

How to copy table structure from one database to another

+4
source share
8 answers

Go to the database in which you want to create a new table and use CREATE TABLE... LIKE..., fully defining the name of the source table.

+8
source

According to the comments, it is not entirely clear what you want to achieve. Are you trying to create a copy of the database (from scratch) or just copy one table structure to another database?

In any case, I would recommend mysqldump .

If you want to copy all tables, you use:

> mysqldump -d $databaseName > $newFile

In addition, if you want to copy only one table, you can use:

> mysqldump -d $databaseName.$tableName > $newFile

...

+7

,

create table new_table_name like existing_table_name;

, .

+3

+2

SQLyog

SQLyog - (/'GUI'/'Frontend') MySQL.

, .

+2

, , .

:

USE TARGET_DB;
CREATE NEW_TABLE LIKE SOURCE_DB.SOURCE_TABLE;
0

I am looking for the same solution. this is my solution, go to the database where you want to create the table as shown below.

CREATE TABLE new_table_name LIKE database.table_name

In this example, a table with AI, Index, Key will be created. it's a bit of a duplicate table structure.

0
source

All Articles