MySQL is not supported for select ... into syntax, using INSERT INTO ... Select replaces the same usage, and here we have a short answer here. The new table exists and does not exist in two situations, using different statements specifically.
1. The new table does not exist
copy table structure i.e. data to new table
CREATE TABLE new_table
select * from Old_talbe;
This method will copy all the content in the old_table, in this way, we need to note that new_table in the old_table of the primary key,extra,auto_increment and other attributes, you need to manually add, Refer to the following modified table, which is the field properties.
Copy only table structure to new table
# The first method, similar to the above, is just a null data record, which gives a false condition
CREATE TABLE new_table
select * from old_table where 1=2;
# The second method of
create table new_table like old_table;
2. The new table exists
copy old table data to new table (assuming two table structure)
INSERT INTO new_table
select * from Old_table;
Copy old table data to new table (assuming two table structures are different)
Insert INTO new_table (field1,field2,.....)
Select Field1,field2,field3 from Old_table;
Copy all data
SELECT * into new_table from old_table;
Copy only table structure to new table
SELECT * into New_talble from old_table where 1=2;
3. Examples
(1) Table does not exist replication
Mysql>show tables;
+-----------------+
| Tables_in_test1 |
+-----------------+
|cpu_stat |
| Test1 |
| Test2 |
| Test3 |
+-----------------+
4rows in Set (0.02 sec)
mysql> Create Tabletest4 as SELECT * from Test1 where 1=0;
Copy table structure only
Queryok, 0 rows affected (0.06 sec)
records:0 duplicates:0 warnings:0
mysql> Create TABLETEST5 as SELECT * from Test1;
Copy all contents of table Test1 to Test5
Queryok, 7 rows affected (0.11 sec)
records:7 duplicates:0
(2) The table already exists replication
Mysql> CREATE TABLE TEST6 (ID int not NULL auto_increment primary key, name varchar);
Query OK, 0 rows affected (0.13 sec)
mysql> insert into TEST6 (name) select name from Test1;
Copy only the Name column
Query OK, 7 rows affected (0.06 sec)
records:7 duplicates:0 warnings:0
mysql> select * FROM t Est6;
+----+-------+
| id | name |
+----+-------+
| 1 | Wu |
| 2 | terry |
| 3 | Tang
|
..... 7 Rows in Set (0.00 sec)