在已经启动正常运行的从库中增加一个需要同步的库: 在执行时,必须保证需要同步的库没有用户使用。 否则会导致同步不一致。
新增同步 upfe 库:
1、停止从库的主从同步进程
- mysql> stop slave;
- mysql> show slave status\G;
- *************************** 1. row ***************************
- Slave_IO_State:
- Master_Host: 192.168.1.87
- Master_User: repluser
- Master_Port: 3306
- Connect_Retry: 60
- Master_Log_File: mysql-bin.000026
- Read_Master_Log_Pos: 122004864
- Relay_Log_File: SYSTEST2-relay-bin.000002
- Relay_Log_Pos: 1102
- Relay_Master_Log_File: mysql-bin.000026
- Slave_IO_Running: No
- Slave_SQL_Running: No
- Replicate_Do_DB:
- Replicate_Ignore_DB:
- Replicate_Do_Table:
- Replicate_Ignore_Table:
- Replicate_Wild_Do_Table: test.%,yhqz.%
- Replicate_Wild_Ignore_Table: mysql.%
- Last_Errno: 0
- Last_Error:
- Skip_Counter: 0
- Exec_Master_Log_Pos: 122004864
- Relay_Log_Space: 1385
- 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: NULL
- 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)
-
- ERROR:
- No query specified
2、从主上面备份需要同步的库:(不需要使用 --master-data=1 参数)
如果使用
--master-data=1 将导致备机的pos 与备份时一致,会导致主备数据丢失。
- [root@SYSTEST1 AB]# mysqldump -R --databases upfe > upfe.sql
- [root@SYSTEST1 AB]# scp upfe.sql 192.168.1.88:/home/ljl/AB
3、备机导入新库upfe
- [root@SYSTEST2 AB]# mysql <upfe.sql
4、修改my.cnf 增加备份库,重启备的数据库服务
- vi /etc/my.cnf
- replicate-wild-do-table=upfe.%
- [root@SYSTEST2 AB]# /etc/init.d/mysql restart
5、启动备的slave
- mysql> show slave status\G;
- *************************** 1. row ***************************
- Slave_IO_State:
- Master_Host: 192.168.1.87
- Master_User: repluser
- Master_Port: 3306
- Connect_Retry: 60
- Master_Log_File: mysql-bin.000026
- Read_Master_Log_Pos: 122004864
- Relay_Log_File: SYSTEST2-relay-bin.000002
- Relay_Log_Pos: 1102
- Relay_Master_Log_File: mysql-bin.000026
- Slave_IO_Running: No
- Slave_SQL_Running: No
- Replicate_Do_DB:
- Replicate_Ignore_DB:
- Replicate_Do_Table:
- Replicate_Ignore_Table:
- Replicate_Wild_Do_Table: test.%,yhqz.%,upfe.%
- Replicate_Wild_Ignore_Table: mysql.%
- Last_Errno: 0
- Last_Error:
- Skip_Counter: 0
- Exec_Master_Log_Pos: 122004864
- Relay_Log_Space: 1510
- 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: NULL
- 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;
阅读(2882) | 评论(1) | 转发(0) |