MySQL ???????????????????binlog??
???????????? ???????[ 2017/4/20 11:16:35 ] ????????????? MySQL
????????MySQL???????
?????????????????SQL??Master?????SQL??Slave???????????????????Master?????????Slave???????Master???????????????????????????????????????????????????????????????????
????MySQL??????????????
????????????
?????????????????????????Master?????????????Slave??Master??????????????У??????????????????????????Master???????????£??????????????????????????ò?????????Slave??Master?????????????????Salve???Master???????????????????????????????????????
???????????????
?????????д?????????????????????????????д????????????ж??Slave??????????????????????Slave???????????????????????????????????????????Slave?????????????????Щ??????????????????Slave?????????????Master??д????????????
???????????????
??????????????????????????????д????????Щ?????????????????????????Щ???????????????????????????????????????????????????????????????????????????????????????
????????????黯
??????????????????????Slave??????????????????????????????????????????????MySQL?洢????
?????塢???????????????
??????????????2????????
????1??scale-up
??????????????????????????????????????????????????????????????????CPU???????????????е??????ж???????????????????????????
????2??scale-out
????????????????????????????????????????????????????????????????????????
???????????????
??????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????
????Slave??Master?????????????????????????????????????????????????????????????????????????????????????????????????Master?в????????????????????????????????
????????д?????
?????????????????????????д?????????????????????????У????Master??д???????????????????????д???Master??????????????????д??Master???????д?Master??Slave????????Master?????滻??Master????????????з?????????д??????????????????????????????????????????????????????
??????????
????MySQL5.6?????????????????????????????binlog????????GTID?????????????????
??????????漰???????binlog??????????
???????????
????1??Master?????????????????????(binary log)?У???????????log-bin????????????Щ???????????????????(binary log events)
????2??Slave???I/O??????Master?е?binary log events??д???????м????(relay log)
????3??Slave?????м?????е?????????м?????е?????????????????????????Σ??????????????洢??????????????????????????(???????)
???????
????1??????????????????汾??λ?????
????2??Master??Slave??????汾????
????3??Master??Slave??????е?????????
????4??Master??????????????Master??Slave??server_id????????????
????????????
???????????
????????????????????????汾??MySQL??????????????汾????????????????????????????????????????????????Docker???棬?????????Docker?????????????????????????????????????????????????????????e?????????????
????????Master
???????????????
????????????my.cnf
???????????my.cnf·??????????????????????????????????????
[mysqld]
## ????server_id??????????IP??????
server_id=100
## ?????????????????????????????mysql??????????
binlog-ignore-db=mysql
## ??????????????????????????????к??壨????????????
log-bin=edu-mysql-bin
## ????session ???????棬????????????????洢??????????????
binlog_cache_size=1M
## ????????????mixed??statement??row?????????statement??
binlog_format=mixed
## ???????????????/????????????????0???????????????
expire_logs_days=7
## ??????????????????????д???????????????????slave??????ж??
## ?磺1062????????Щ?????????1032??????????????????????????
slave_skip_errors=1062
????????????????mysql
??????????????
?????????????????????????????е????????????????????????
????1????Master??????????????е????
????2????Slave??????м?????е??????
????????????
????1?????????????
??????Master????е?SQL?????Slave?????????????MySQL?????????????????Ч??????????????????????????????????????е????
????2???????е????
?????????????????Slave???????????????Slave???????顣??MySQL5.0??????
????3?????????????
??????????????????????????????????????????????????????????е????
??????????????????????
????CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
????GRANT REPLICATION SLAVE?? REPLICATION CLIENT ON *.* TO 'slave'@'%';
?????????????????????REPLICATION SLAVE????REPLICATION CLIENT???
????????Slave
???????????????
????????????my.cnf
[mysqld]
## ????server_id??????????IP??????
server_id=101
## ?????????????????????????????mysql??????????
binlog-ignore-db=mysql
## ????????????????????Slave???????Slave??Master????
log-bin=edu-mysql-slave1-bin
## ????session ???????棬????????????????洢??????????????
binlog_cache_size=1M
## ????????????mixed??statement??row?????????statement??
binlog_format=mixed
## ???????????????/????????????????0???????????????
expire_logs_days=7
## ??????????????????????д???????????????????slave??????ж??
## ?磺1062????????Щ?????????1032??????????????????????????
slave_skip_errors=1062
## relay_log?????м????
relay_log=edu-mysql-relay-bin
## log_slave_updates???slave?????????д???????????????
log_slave_updates=1
## ??????????(????????????)
read_only=1
???????Slave?????Slave??Master???????????bin_log??????????????mysql
???????Master??Slave????
????????????????
???????Master??Slave????????????????????????????
???????????Master??
??????Master?????
????show master status;
????????·???????File?к?Position?е??
????????Slave??????Master???
??????Slave?????
????change master to master_host='192.168.1.100'?? master_user='slave'?? master_password='123456'?? master_port=3306?? master_log_file='edu-mysql-bin.000001'?? master_log_pos=1389?? master_connect_retry=30;
??????????е??????????
????master_host=’192.168.1.100′ ## Master??IP???
????master_user=’slave’ ## ???????????????????Master????????????
????master_password=’123456′ ## ????????????????
????master_port=3306 ## Master???????????
????masterlogfile=’edu-mysql-bin.000001′ ##???Slave?????????????????????????Master??????????????File??Σ?
????masterlogpos=429 ## ?????POSITION????????Master??????????????Position??Σ?
????masterconnectretry=30 ##??????????????????????????????????????ú????????λ???????????60????????????????
??????????????????
??????Slave?????????
????show slave status;
?????????SlaveIOState???? SlaveIORunning??SlaveSQLRunning??No??????Slave????п????????????SlaveIORunning??SlaveSQLRunning??Yes????????????????
?????塢???????????
??????Slave?????????
????start slave;
????????????????????????SlaveIORunning??SlaveSQLRunning??Yes?????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11