MySQL 我想复制一个数据库中包含的表并插入到另一个数据库表中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8754607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I want to copy table contained from one database and insert onto another database table
提问by user1031092
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?
我想将表的架构以及该表中的数据复制到实时服务器上另一个数据库中的另一个数据库表。我怎么能这样做?
回答by
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;
回答by HukeLau_DABA
or just CREATE TABLE db2.table SELECT * FROM db1.table in MySQL 5
或者只是在 MySQL 5 中 CREATE TABLE db2.table SELECT * FROM db1.table
回答by billynoah
In BASH you can do:
在 BASH 中,您可以执行以下操作:
mysqldump database_1 table | mysql database_2
回答by Rashi Goyal
CREATE TABLE db2.table_new AS SELECT * FROM db1.table_old
创建表 db2.table_new AS SELECT * FROM db1.table_old
回答by Hemant Shori
If you just want Structure to be copied simply use
如果您只想复制结构,只需使用
CREATE TABLE Db_Name.table1 LIKE DbName.table2;
CREATE TABLE Db_Name.table1 LIKE DbName.table2;
Ps > that will not copy schema and data
ps > 不会复制架构和数据
回答by Vishnu More
simply use -
只需使用 -
CREATE TABLE DB2.newtablename SELECT * FROM DB1.existingtablename;
创建表 DB2.newtablename SELECT * FROM DB1.existingtablename;