I want to copy table contained from one database and insert onto another database table

MysqlSqlMysqldump

Mysql Problem Overview


I want to copy a table's schema as well as the data within that table to another database table in another database on a live server. How could I do this?

Mysql Solutions


Solution 1 - Mysql

If you want to copy a table from one Database to another database , You can simply do as below.

CREATE TABLE db2.table LIKE db1.table;
INSERT INTO db2.table SELECT * FROM db1.table;

Solution 2 - Mysql

or just CREATE TABLE db2.table SELECT * FROM db1.table in MySQL 5

Solution 3 - Mysql

In BASH you can do:

mysqldump database_1 table | mysql database_2

Solution 4 - Mysql

CREATE TABLE db2.table_new AS SELECT * FROM db1.table_old

Solution 5 - Mysql

If you just want Structure to be copied simply use

CREATE TABLE Db_Name.table1 LIKE DbName.table2;

Ps > that will not copy schema and data

Solution 6 - Mysql

simply use -

CREATE TABLE DB2.newtablename SELECT * FROM DB1.existingtablename;

Solution 7 - Mysql

In Commandline:

mysqldump -h localhost -u username -ppassword [SCHEMA] --tables [TABLE] | mysql -h otherhost -u username -ppassword [SCHEMA2]

This will copy table inside SCHEMA on localhost to SCHEMA2 on otherhost.

localhost and otherhost are just hostname and might be same or different.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1031092View Question on Stackoverflow
Solution 1 - Mysqluser319198View Answer on Stackoverflow
Solution 2 - MysqlHukeLau_DABAView Answer on Stackoverflow
Solution 3 - MysqlEaten by a GrueView Answer on Stackoverflow
Solution 4 - MysqlRashi GoyalView Answer on Stackoverflow
Solution 5 - MysqlHemant ShoriView Answer on Stackoverflow
Solution 6 - MysqlVishnu MoreView Answer on Stackoverflow
Solution 7 - MysqlDrGeneralView Answer on Stackoverflow