我希望从一个数据库复制包含的表,并将其插入到另一个数据库表中

我希望将一个表的模式以及该表中的数据复制到活动服务器上另一个数据库中的另一个数据库表中。我怎么能这么做?

86099 次浏览

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;

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

simply use -

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

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

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

In BASH you can do:

mysqldump database_1 table | mysql database_2

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.