主服务器上
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表
- 在主上机器,进入到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>
- 进入到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>
- 查看表,有几个表
mysql> show tables;
+-----------------+
| Tables_in_zrlog |
+-----------------+
| comment |
| link |
| log |
| lognav |
| plugin |
| tag |
| type |
| user |
| website |
+-----------------+
9 rows in set (0.00 sec)
mysql>
- 查看表有多少行,会看到website里面有9行数据
- select count(*) from website;
mysql> select count(*) from website;
+----------+
| count(*) |
+----------+
| 9 |
+----------+
1 row in set (0.00 sec)
mysql>
- 这时候再来查看 从上 的zrlog表上的数据,会看到是同样的
- 将主机器上的 表作一个删除操做
- 再来查看 主机器 的表和 从机器 上表都会被删除了
- 如果误操做了,好比在从机器误删除了,再去主上删除相同的数据,就会有可能致使主从失败
- 这时在从机器上 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
- 若实在只能从头作主从的