我们计划使用MySQL复制主从过程将现有的MySQL数据库迁移到新服务器。
不幸的是,这将花费大量时间,因此我们考虑对MySQL中心db进行转储,在新的mysql上恢复转储,然后设置主从过程。
恢复原始数据库的转储后使用主从过程是否会覆盖新服务器上的数据,从而浪费转储/还原过程的时间?或者,主/从过程会复制在转储发生后添加到旧服务器的数据吗?
我正在使用MySQL 5.1的Debian压缩。
发布于 2012-08-28 21:24:38
是的,它会覆盖奴隶的数据。但是,您可以设置复制,以便从转储的时间点开始,并使其滚出自转储加载到从服务器上以来的所有更改。
对于这个例子,让我们假设
这就是你要做的
上的二进制日志记录
步骤01-a)将此添加到母版上的/etc/my.cnf
[mysqld]
server-id=101120
log-bin=mysql-bin步骤01-b) # service mysql restart
在STEP01之后,您应该在/var/lib/mysql中看到mysql-bin.0001和mysql-bin.index。
在主服务器上,您可以转储数据并记录发生时间的时间点。
# service mysql restart --skip-networking --skip-grants
# mysqldump --single-transaction --master-data=2 --all-databases --routines --triggers > MySQLData.sql
# service mysql restart这样做是记录主日志文件并在mysqldump作为注释启动时定位。当您查看第22行时,可以明显地看到它:
# head -22 MySQLData.sql | tail -1中
执行mysql客户端,将mysqldump加载到Slave的mysql实例中
# mysql -h10.1.1.30 -uroot -p < MySQLData.sql上创建MySQL复制用户
# mysql -uroot -p -e"GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'replicator'@'10.64.51.%' IDENTIFIED BY 'replpassword'"设置从服务器
将此添加到奴隶上的/etc/my.cnf中
[mysqld]
server-id=101130和# service mysql restart
上设置复制
转到mysql客户端并运行以下命令
mysql> CHANGE MASTER TO
MASTER_HOST='10.1.1.20',
MASTER_PORT=3306,
MASTER_USER='replicator',
MASTER_PASSWORD='replpassword',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=1;在STEP02中,我提到了使用
# head -22 MySQLData.sql | tail -1你应该看到这样的东西:
#CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000015', MASTER_LOG_POS=122957100;将它作为命令运行在从服务器上的mysql客户机中。
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000015', MASTER_LOG_POS=122957100;之后,运行以下命令
mysql> SHOW SLAVE STATUS\G你应该看到这样的东西:
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.64.113.232
Master_User: replicant
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000015
Read_Master_Log_Pos: 122957100
Relay_Log_File: relay-bin.003666
Relay_Log_Pos: 122957100
Relay_Master_Log_File: mysql-bin.000015
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 106
Relay_Log_Space: 106
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)使用以下内容启动复制:
mysql> START SLAVE;之后,再次运行此命令。
mysql> SHOW SLAVE STATUS\G如果你看到这个
Slave_IO_Running: Yes
Slave_SQL_Running: Yes恭喜你,MySQL复制成功了!
https://dba.stackexchange.com/questions/23297
复制相似问题