在mysql中主从同步是比较常用的一种数据库集群方式,但是主库上数据库很多,只是压力大的库只有一个,所以在主从同步中需要把压力大的库单独做一个从库,减轻主库压力,这时就需要设计到从库只同步压力大的一个库,其他库不需要同步的问题了。主从同步可以参考:https://www.wulaoer.org/?p=3079
我这里主从读写分离已经部署好了,只需要把在从库上进行过滤即可。
[mysqld] .................... replicate-wild-do-table=wulaoer.* #指定要复制的库 replicate-wild-ignore-table=wulaoer.w** #过滤不需要同步的表
配置文件中wulaoer这个库是我需要同步的,其中w开头的表我需要过滤,从库不需要同步。配置好后保存重启一下mysql即可。然后在看一下监控复制状态;
mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.16.10.139 Master_User: mysql_slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000034 Read_Master_Log_Pos: 947195 Relay_Log_File: mysql_slave01-relay-bin.000006 Relay_Log_Pos: 183904 Relay_Master_Log_File: mysql-bin.000034 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: wulaoer.* #这里是只同步的库 Replicate_Wild_Ignore_Table: wulaoer.w* #过滤的表 Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 947195 Relay_Log_Space: 184119 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: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 10139 Master_UUID: b20916bd-22b6-11ed-bbd8-525400049163 Master_Info_File: /usr/local/mysql/var/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) ERROR: No query specified
下面我们在主库上创建一个test库,看一下从库上是否会同步过去。
#主库 mysql> create database test; Query OK, 1 row affected (0.01 sec) #从库 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | wulaoer | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
说明没有只有wulaoer这个库可以同步过来其他的库无法同步,整个实验做完了,没有了,可以看看其他的吧。
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏