[英]How to Migrate MySQL with tons of data?
So I want a service to start using a new MySQL instance like nothing happened.所以我希望服务开始使用新的 MySQL 实例,就像什么都没发生一样。 I just want to change the DB URL and credentials and have my service working like it was working.我只想更改 DB URL 和凭据,让我的服务像正常工作一样工作。
The problem is that we want to minimize the downtime.问题是我们希望最大限度地减少停机时间。
How if my database has 30GB of data?如果我的数据库有 30GB 的数据怎么办?
One of our solutions is:我们的解决方案之一是:
We are just not sure how to make sure it's fully synchronized and if the new instance can become independent after it was a follower.我们只是不确定如何确保它完全同步,以及新实例在成为跟随者之后是否可以变得独立。
How to make sure it's fully synchronized and how to make it independent?如何确保它完全同步以及如何使其独立?
First you initialize the replica with a snapshot from the master.首先,您使用来自主服务器的快照初始化副本。 There are instructions here: https://dev.mysql.com/doc/refman/5.7/en/replication-howto.html这里有说明: https://dev.mysql.com/doc/refman/5.7/en/replication-howto.html
To make sure it's synchronized before you cut over:要确保在切换之前同步:
set global read_only=1;
一个好方法是set global read_only=1;
show master status\G
After you enable read_only
there shouldn't be any new changes, so the binary log will stop growing (note users with SUPER privilege can still write changes, so you might need to prevent this with set global super_read_only=1;
too).查看主节点上的二进制日志 position: show master status\G
启用read_only
后不应有任何新更改,因此二进制日志将停止增长(注意具有 SUPER 权限的用户仍然可以写入更改,因此您可能需要也可以使用set global super_read_only=1;
防止这种情况)。show slave status\G
When Master_Log_File
and Exec_Master_Log_Pos
catch up to the values you observed on the primary, then it's caught up.查看副本上的二进制日志 position: show slave status\G
当Master_Log_File
和Exec_Master_Log_Pos
赶上您在主服务器上观察到的值时,它就赶上了。reset slave;
告诉副本忘记它的复制订阅: reset slave;
I recommend that you practice this a few times in a test environment before attempting it on your real system.我建议您在实际系统上尝试之前在测试环境中练习几次。 Once you are familiar with the steps, it should be possible to do it pretty quickly.一旦熟悉了这些步骤,应该可以很快完成。 I would be confident of doing it in less than one minute of downtime.我有信心在不到一分钟的停机时间内做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.