选择&使用MySQL跨多个数据库插入 [英] Select & Insert across multiple databases with MySQL
本文介绍了选择&使用MySQL跨多个数据库插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在同一服务器上的2个不同数据库中有2个相同的表.将数据从表复制到另一个表的最佳方法是什么?
I have 2 identical tables in 2 different databases that reside on the same server. What would be the best way to copy data from table to another?
推荐答案
使用:
INSERT INTO db1.table1
SELECT *
FROM db2.table2 t2
WHERE NOT EXISTS(SELECT NULL
FROM db1.table1 t1
WHERE t1.col = t2.col)
存在被简化了,但是如果有主键/auto_increment可以担心/等,您就省去了.
The exists is simplified, but you left out if there's a primary key/auto_increment to worry about/etc.
这篇关于选择&使用MySQL跨多个数据库插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文