The so-called insect replication is for a table of data, the rapid replication and insert into the required table, in order to have a short period of time “large amount of data” for testing or other special occasions, such as:

  • To migrate data from one table to another, or to migrate a portion of specified data to another table.

  • Copy a large amount of data from one table to another table;

  • Copy data from a table to its own table to produce large amounts of data;

Insert into user (name, age) select name,age from test; Insert into user (name, age) select name,age from user; Requirements: 1. The number of fields in the insert statement is the same as the number of fields in the SELECT statement. 2, insert statement field type, same as the select statement field type. 3. Field names can be different between tables, as long as the above two points are met.Copy the code

Select * from test where user = ‘test’;

mysql> desc test; +-------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | YES | | NULL | | | sex | varchar(1) | YES | | NULL | | | age | tinyint(3) unsigned | YES | | NULL | | +-------+---------------------+------+-----+---------+----------------+ mysql> desc user; +-------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | YES | | NULL | | | age | tinyint(3) unsigned | YES | | NULL | | +-------+---------------------+------+-----+---------+----------------+ mysql> select * from test; + - + -- -- -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- -- -- + | | id name | sex | age | + - + -- -- -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- -- -- + | 1 | name1 | | 5 male | | 2 | name2 | Female 10 | | | 3 | name3 | male 15 | | | | 4 name4 | | | + 20 male - + -- -- -- -- -- -- - + -- -- -- -- -- - + -- -- -- -- -- - + mysql > select * from the user. Mysql > insert into user (name, age) select name, age from test; Query OK, 4 rows affected (0.00 SEC) mysql> select * from user; +----+-------+------+ | id | name | age | +----+-------+------+ | 1 | name1 | 5 | | 2 | name2 | 10 | | 3 | name3 | 15 | | 4 | name4 | 20 | +----+-------+------+Copy the code