Chinaunix首页 | 论坛 | 博客
  • 博客访问: 39967
  • 博文数量: 5
  • 博客积分: 1555
  • 博客等级: 上尉
  • 技术积分: 57
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-03 17:42
个人简介

既然选择了远方,便只顾风雨兼程。

文章分类

全部博文(5)

文章存档

2012年(4)

2010年(1)

我的朋友

分类: Mysql/postgreSQL

2012-06-14 18:05:45

在已经启动正常运行的从库中增加一个需要同步的库: 在执行时,必须保证需要同步的库没有用户使用。 否则会导致同步不一致。
新增同步 upfe 库:
 1、停止从库的主从同步进程  

点击(此处)折叠或打开

  1. mysql> stop slave;
  2.  mysql> show slave status\G;
  3. *************************** 1. row ***************************
  4.                Slave_IO_State:
  5.                   Master_Host: 192.168.1.87
  6.                   Master_User: repluser
  7.                   Master_Port: 3306
  8.                 Connect_Retry: 60
  9.               Master_Log_File: mysql-bin.000026
  10.           Read_Master_Log_Pos: 122004864
  11.                Relay_Log_File: SYSTEST2-relay-bin.000002
  12.                 Relay_Log_Pos: 1102
  13.         Relay_Master_Log_File: mysql-bin.000026
  14.              Slave_IO_Running: No
  15.             Slave_SQL_Running: No
  16.               Replicate_Do_DB:
  17.           Replicate_Ignore_DB:
  18.            Replicate_Do_Table:
  19.        Replicate_Ignore_Table:
  20.       Replicate_Wild_Do_Table: test.%,yhqz.%
  21.   Replicate_Wild_Ignore_Table: mysql.%
  22.                    Last_Errno: 0
  23.                    Last_Error:
  24.                  Skip_Counter: 0
  25.           Exec_Master_Log_Pos: 122004864
  26.               Relay_Log_Space: 1385
  27.               Until_Condition: None
  28.                Until_Log_File:
  29.                 Until_Log_Pos: 0
  30.            Master_SSL_Allowed: No
  31.            Master_SSL_CA_File:
  32.            Master_SSL_CA_Path:
  33.               Master_SSL_Cert:
  34.             Master_SSL_Cipher:
  35.                Master_SSL_Key:
  36.         Seconds_Behind_Master: NULL
  37. Master_SSL_Verify_Server_Cert: No
  38.                 Last_IO_Errno: 0
  39.                 Last_IO_Error:
  40.                Last_SQL_Errno: 0
  41.                Last_SQL_Error:
  42. 1 row in set (0.00 sec)
  43.  
  44. ERROR:
  45. No query specified

2、从主上面备份需要同步的库:(不需要使用 --master-data=1 参数) 如果使用 --master-data=1  将导致备机的pos 与备份时一致,会导致主备数据丢失。

点击(此处)折叠或打开

  1. [root@SYSTEST1 AB]# mysqldump -R --databases upfe > upfe.sql
  2. [root@SYSTEST1 AB]# scp upfe.sql 192.168.1.88:/home/ljl/AB
3、备机导入新库upfe

点击(此处)折叠或打开

  1. [root@SYSTEST2 AB]# mysql <upfe.sql
4、修改my.cnf 增加备份库,重启备的数据库服务

点击(此处)折叠或打开

  1. vi /etc/my.cnf
  2. replicate-wild-do-table=upfe.%
  3. [root@SYSTEST2 AB]# /etc/init.d/mysql restart
5、启动备的slave

点击(此处)折叠或打开

  1. mysql> show slave status\G;
  2. *************************** 1. row ***************************
  3.                Slave_IO_State:
  4.                   Master_Host: 192.168.1.87
  5.                   Master_User: repluser
  6.                   Master_Port: 3306
  7.                 Connect_Retry: 60
  8.               Master_Log_File: mysql-bin.000026
  9.           Read_Master_Log_Pos: 122004864
  10.                Relay_Log_File: SYSTEST2-relay-bin.000002
  11.                 Relay_Log_Pos: 1102
  12.         Relay_Master_Log_File: mysql-bin.000026
  13.              Slave_IO_Running: No
  14.             Slave_SQL_Running: No
  15.               Replicate_Do_DB:
  16.           Replicate_Ignore_DB:
  17.            Replicate_Do_Table:
  18.        Replicate_Ignore_Table:
  19.       Replicate_Wild_Do_Table: test.%,yhqz.%,upfe.%
  20.   Replicate_Wild_Ignore_Table: mysql.%
  21.                    Last_Errno: 0
  22.                    Last_Error:
  23.                  Skip_Counter: 0
  24.           Exec_Master_Log_Pos: 122004864
  25.               Relay_Log_Space: 1510
  26.               Until_Condition: None
  27.                Until_Log_File:
  28.                 Until_Log_Pos: 0
  29.            Master_SSL_Allowed: No
  30.            Master_SSL_CA_File:
  31.            Master_SSL_CA_Path:
  32.               Master_SSL_Cert:
  33.             Master_SSL_Cipher:
  34.                Master_SSL_Key:
  35.         Seconds_Behind_Master: NULL
  36. Master_SSL_Verify_Server_Cert: No
  37.                 Last_IO_Errno: 0
  38.                 Last_IO_Error:
  39.                Last_SQL_Errno: 0
  40.                Last_SQL_Error:
  41. 1 row in set (0.00 sec)
  42.  
  43. mysql> start slave;


阅读(2800) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

lonelysoul0112012-10-16 15:31:18

补充新找的方法:
1、 停止从库复制
2 、备份主库upfe  并记录复制点
3 、同步从库使用start slave until 命令 同步其他数据到刚才 upfe 的复制点后停止
4 、在从库导入upfe
5 、开启正常同步