前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >17.5 测试主从同步

17.5 测试主从同步

作者头像
运维小白
发布2018-02-07 10:42:30
6190
发布2018-02-07 10:42:30
举报
文章被收录于专栏:运维小白运维小白

主服务器上

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
      • 若实在只能从头做主从的
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 主服务器上
  • 从服务器上
  • 测试主从
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档