17.5 测试主从同步

主服务器上

binlog-do-db=            //仅同步指定的库(多个库,可以用“ , ”逗号分隔)——>英文的逗号 , 
binlog-ignore-db=     //忽略指定库

从服务器上

replicate_do_db=          //仅同步指定的库
replicate_ignore_db=     //忽略指定库
replicate_do_table=         //仅同步指定的表
replicate_ignore_table=    //忽略指定表,
    - 例如:有一个临时表,写的数据非常快,数据也大,每天都需要删除这时就可以更新删除这个,那么就不需要每天去做同步
 replicate_wild_do_table=   //如aming.%, 支持通配符%  指定同步靠谱的匹配  同步表   
replicate_wild_ignore_table=   //如aming.%, 支持通配符%  指定同步靠谱的匹配  忽略表
  • 进行从服务器的配置时尽量使用参数“replicate_wild_”,使匹配更精确,提升使用性能。

测试主从

  • 主上 mysql -uroot aming
  • select count(*) from db;
  • truncate table db;
  • 到从上 mysql -uroot aming
  • select count(*) from db;
  • 主上继续drop table db;
  • 从上查看db表
  1. 在主上机器,进入到mysql
[root@hanfeng ~]# mysql -uroot -phanfeng
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5562
Server version: 5.6.35-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
  1. 进入到zrlog库里面
mysql> use zrlog;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
  1. 查看表,有几个表
  • show tables;
mysql> show tables;
+-----------------+
| Tables_in_zrlog |
+-----------------+
| comment         |
| link            |
| log             |
| lognav          |
| plugin          |
| tag             |
| type            |
| user            |
| website         |
+-----------------+
9 rows in set (0.00 sec)

mysql> 
  1. 查看表有多少行,会看到website里面有9行数据
  • select count(*) from website;
mysql> select count(*) from website;
+----------+
| count(*) |
+----------+
|        9 |
+----------+
1 row in set (0.00 sec)

mysql> 

  1. 这时候再来查看 从上 的zrlog表上的数据,会看到是一样的

  1. 将主机器上的 表做一个删除操作
  • truncate table website;
    • truncate 表示 清空

  1. 再来查看 主机器 的表和 从机器 上表都会被删除了

  • 若是误操作了,比如在从机器误删除了,再去主上删除相同的数据,就会有可能导致主从失败
    • 这时在从机器上 start slave;
    • 然后在start slave;
    • 再来查看show slave status\G
    • 若是还是失败,则只能 重新做主从了
      • 重新主从
      • 在主机器的数据库上 show mater status; 查看文件大小
      • 然后在从机器上先stop slave;
        • 然后直接change master to master_host='192.168.202.130', master_user='repl', master_password='hanfeng', master_log_file='hf123.000001', master_log_pos=10549;
          • 因为基本还没做什么操作的,数据还是一致的,直接改下数据大小就行
      • 然后在从机器上 start slave;
      • 再来查看 show slave status\G 看是否为两个Yes
      • 若实在只能从头做主从的

转载于:https://my.oschina.net/u/3707314/blog/1611562

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值