下面是某业务库的迁移过程, 从Source Master/Slave集群迁移至Target MHA集群.
前期准备, 配置数据从Source Master复制到Target Master, 即Target Master成为Source Master的Slave(若Target Master是新库的话, 还可添加replicate-do-db=name过滤条件).
迁移开始时, 在Source Master上执行flush no_write_to_binlog tables, 和flush tables with read lock.
在Target Master上查看延时为0时, 执行flush binary logs. 然后stop slave, 和reset slave all, 清除Source Master至Target Master的复制关系.
再后, 依次重启各应用节点, 切换至Target Master新数据源.
最后在Source Master上unlock tables, 至此迁移结束.
该过程中的主角flush tables with read lock, 其含义为Closes all open tables and locks all tables for all databases with a global read lock, 即在MySQL数据库Server层, 获取一个全局读锁.
那么配角flush no_write_to_binlog tables, 其含义为Closes all open tables, forces all tables in use to be closed, 起到加速flush tables wit