Alex Rivera | Logout

In MySQL, how to copy the content of one table to another table within the same database?

Asked 2010-02-26T17:50:07.563
153

I am new to MySQL. I would like to copy the content of one table to another table within the same database. Basically, I would like to insert to a table from another table. Is there easy way of doing this?

Edit
Report

1 Answer

34

If table1 is large and you don't want to lock it for the duration of the copy process, you can do a dump-and-load instead:

CREATE TABLE table2 LIKE table1;

SELECT * INTO OUTFILE '/tmp/table1.txt' FROM table1;
LOAD DATA INFILE '/tmp/table1.txt' INTO TABLE table2;
answered 2010-02-26T19:13:04.860

Your Answer