How to copy MySQL data tables and table structures bitsCN.com
How to copy MySQL data tables and table structures
This section describes how to copy MySQL, table structure, and fields. You can also copy data from one table to another.
1. copy the table structure (syntax: creata table old table select * from NEW table)
create table t1( id int unsigned auto_increment primary key, name varchar(32) not null default '', pass int not null default 0 );
Desc view table structure
Create table t2 copy table t1 table structure create table t2 select * from t1;
View table structure in desc t2
Note: The fields in the two tables have the same structure, but the primary key and auto-increment auto_increment are absent. Therefore, this method is not recommended, so how can we create two identical tables? there are certainly some solutions, as shown in the following statement.
create table t2 like t1;
This allows you to create a table that is exactly the same as t2 and t1.
2. specify the field to copy the table structure
Syntax: create table new table select field 1, field 2... From old table
3. Copy table data
Suppose you want to copy all the data in table t1 to insert into t2 select * from t1 in table t2. if you only want to copy a field insert into t2 (Field 1, field 2) select field 1, field 2 from t1;
BitsCN.com