How to copy a table from one mysql database to another mysql database How to copy a table from one mysql database to another mysql database mysql mysql

How to copy a table from one mysql database to another mysql database


If you need to copy the table on the same server you can use this code:

USE db2;CREATE TABLE table2 LIKE db1.table1;INSERT INTO table2      SELECT * FROM db1.table1;

It's copy+pasted from here:codingforums.com

It's not my solution, but I find it useful.


I'd dump it. Much less complicated than anything PHP based.

mysqldump -u user1 -ppassword1 databasename > dump.sqlmysql -u user2 -ppassword2 databasename < dump.sql

MySQL reference: 4.5.4. mysqldump — A Database Backup Program


mysqldump -u user1 -ppassword1 databasename TblName | mysql -u user2 -ppassword2 anotherDatabase

It all can be done in a single command.