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

北战南征 提交于 2019-11-27 04:58:24

问题


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?


回答1:


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;



回答2:


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




回答3:


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




回答4:


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




回答5:


In BASH you can do:

mysqldump database_1 table | mysql database_2



回答6:


simply use -

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



来源:https://stackoverflow.com/questions/8754607/i-want-to-copy-table-contained-from-one-database-and-insert-onto-another-databas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!