Summary of the method of replicating table structure in mysql

  • 2020-06-23 02:04:08
  • OfStack

mysql USES the command line to copy the table structure there are mainly 1 of the following methods:

1. Only copy the table structure to the new table


CREATE TABLE  The new table  SELECT * FROM  The old table  WHERE 1=2  

or


CREATE TABLE  The new table  LIKE  The old table   

2. Copy the table structure and data to the new table


CREATE TABLE  The new table  SELECT * FROM  The old table  

3. Copy the data of the old table to the new table (assuming 1 sample structure of the two tables)


INSERT INTO  The new table  SELECT * FROM  The old table   

4. Copy the data of the old table to the new table (assuming that the two tables have different structure)


INSERT INTO  The new table ( field 1, field 2,.......) SELECT  field 1, field 2,...... FROM  The old table  


Related articles: