简体   繁体   English

使用mysqldump从实时站点中的其他数据库导入MySQL表会引起麻烦吗?

[英]Importing MySQL tables from other database in live site with mysqldump can cause trouble?

Scenario: I want to replicate MySQL tables from one database to other database. 场景:我想将MySQL表从一个数据库复制到另一个数据库。

Possible best solution: May be to use MySQL Replication feature. 可能的最佳解决方案:可能是使用MySQL复制功能。 Current solution on what I'm working as workaround (mysqldump) because can't spend time to learn about Replication in current deadline. 关于我正在解决的问题的当前解决方案(mysqldump),因为无法花时间在当前期限内了解复制。

So currently I'm using command like this: 所以目前我正在使用这样的命令:

mysqldump -u user1 -ppassword1 --single-transaction SourceDb TblName | mysql -u user2 -ppassword2 DestinationDB

Based on some tests, it seems to be working fine. 根据一些测试,它似乎运行良好。 While running above command, I run ab command with 1000 requests on destination site and tried accessing the site from browser also. 在执行上述命令时,我在目标站点上运行了1000个请求的ab命令,并尝试从浏览器访问该站点。

My concern is for destination live site on which we are importing data with whole table (which will internally drop existing table and create new one with new data). 我关心的是目标实时站点,我们将在该站点上导入整个表的数据(它将在内部删除现有表并使用新数据创建一个新表)。

Can I be sure that live site won't break while this process or is there any risk factor? 我可以确定在此过程中实时站点不会中断,还是有任何风险因素? If yes then can that be resolved? 如果是,那可以解决吗?

As such you already admitted replication is the best solution here, I'd agree to that. 因此,您已经承认复制是此处的最佳解决方案,我同意这一点。

You said you have 1000 requests on "Destination" side? 您说您在“目的地”方面有1000个请求? Are these 1000 connections to Destination read-only? 与目标的这1000个连接是只读的吗? Ofcourse dropping and recreating table isn't a right choice here for active connections. 当然,对于活动连接,删除和重新创建表不是正确的选择。

Can suggest one improvement. 可以建议一种改善。 Instead of directly loading to table, load to different database and swap tables. 而不是直接加载到表,而是加载到不同的数据库和交换表。 This should be quicker as far as connections to Destination database/tables are concerned. 就与目标数据库/表的连接而言,这应该更快。

  • create new table different database 创建新表不同的数据库

mysqldump -u user1 -ppassword1 --single-transaction -hSOURCE_HOST SourceDb TblName | mysql -uuser2 -ppassword2 -hDESTINATION_HOST DB_New

(Are you sure you don't have "-h " here?) (您确定这里没有“ -h”吗?)

  • Swap the tables 交换桌子

rename table DB.TblName to DB.old_TblName, DB_New.new_TblName to DestinationDB.TblName;

If you're on same host (which I dont think so), you might want to use pt-online-schema-change and swap tables! 如果您在同一台主机上(我不这么认为),则可能要使用pt-online-schema-change和swap表!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM