如何从一个表中转储数据并插入到另一个表中
我有两个数据库。我想从第一个数据库中的一个表中转储数据,然后插入到第二个数据库中具有另一个名称的另一个表中。
因此,我的 DB1 包含表 tbl1 和 tabl2,DB2 包含表 tbl3 和 tbl4。我知道 tabl1 和 tabl3 具有相同的结构。如何使用 mysqldump 命令将数据从一个复制到另一个?
我尝试过这样做,但行不通。
mysqldump --user root --password=password --no-create-info DB1 tbl1 > c:/dump.sql
mysql --user root --password=password DB2 tbl3 < c:/dump.sql
I have two databases. I want to dump data from one table in 1st database and insert to another table with an another name in 2nd database.
So I have DB1 that has tables tbl1 and tabl2, and DB2 that has tables tbl3 and tbl4. I know that tabl1 and tabl3 have the same structure. How to copy data from one to another by using mysqldump command?
I've tried to do this, but it's not work.
mysqldump --user root --password=password --no-create-info DB1 tbl1 > c:/dump.sql
mysql --user root --password=password DB2 tbl3 < c:/dump.sql
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于表名不同,这将不起作用
如果两个数据库位于使用相同守护程序的同一服务器中,
,如果 DB2 中不存在 tbl1,则可以直接使用,
伪代码:
This is not going to work due to different table name
if both database are sitting in the same server using the same daemon, you can directly
if tbl1 is not existing in DB2,
pseudo code for this :
我在 Linux shell 命令行中使用
它,将其从本地主机传输到远程主机,即整个数据库。
I am using in a linux shell command line
this transfers it from the local host to a remote host, the whole database.
如果您还想复制表的内容,您可以执行以下操作:
如果您必须将表从一个数据库复制到另一个数据库,则使用以下内容
它对我有用,因为转储单个表并导入会引发 MariaDB 语法错误
IF you want to also copy the contents of the table you can do:
If you have to copy table from one database to another database then use following
It works for me as dumping single table and importing was throwing syntax error with MariaDB