如何将表从一个数据库复制到不同服务器的另一个数据库 [英] How to copy tables from one DB to another DB Of Different server
问题描述
我有两台服务器,我们要每天将一些表从一台服务器的 DB1 复制到另一台服务器的 DB2
I Have Two servers where we want to copy some tables from DB1 Of one server to DB2 Of another serve on daily basis
在 DB1 上我们会定期更新数据库
On DB1 We are updating database regularly
任何一辆面包车都有相同的 Idia
Van any one have Idia about same
推荐答案
如果你想保持服务器/数据库同步,那么最好的选择是主/从复制.
If you want to keep both server/db in sync then best option is master/slave replication.
但是如果你不想设置复制,那么你可以使用一个脚本,它会每天从 server1/db1 进行转储并在 server2/db2 上恢复,即使你可以避免通过 --single-transaction
选项.
But if you don't want to setup replication then you can use a script, which will take dump from server1/db1 and restore on server2/db2 on daily basis, even you can avoid locking on your production server by --single-transaction
option.
您可以在脚本中使用以下语句,并通过 cronjob 在较少的交通时间(夜间)内安排它.
You can use below statement in your script and schedule it in less traffic hours (night) through cronjob.
mysqldump --single-transaction -h server1_ip -uroot -proot123 mydb1 table1 table2 table3 | mysql -h server2_ip -uroot -p root123 mydb2
这篇关于如何将表从一个数据库复制到不同服务器的另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!