一:进行bin-log日志配置
1设置bin-log日志
[mysqld]
log-bin=//路径 #<===红色的加粗的省去
server-id = 1 #主库
2.检查配置登录数据库
show variables like "%log_bin%"
show variables like "%server%"
3.创建账号并赋予权限
create user ‘Tom‘@‘111.111.111.111‘ identified by ‘密码‘
grant replication slave on *.* to [email protected]‘111.111.111.111‘;
4.刷新权限:
flush privileges;
二:导库操作:
申请锁表(测试环境不用做这一步)
- flush tables with read lock;
- 拿到位置点:查看状态
show master status;
- 导出数据库
mysqldump -uroot -p123456 -B -A >/tmp/new.sql
--all-databases , -A
--databases , -B
- 发送数据
scp all.sql [email protected]:/tmp
- unlock table; //解锁(测试环境不用做这一步)
三:(从库my.cnf配置)
1.是否进行开启bin-log
情况1:
级联同步a->b->c那中间的B就要开始log-bin。
情况2:
全备的情况-> 在从库做数据备份,数据库备份必须要有全备和binlog日志,才是完整的备份
2.server-id=3 #server-id 不要和主库一样
3.重启从库
4.查看状态
show variables like "%log_bin%"
show variables like "%server%"
四:从库进行恢复
mysql -uroot -p123456 < /tmp/new.sql
五:告诉从库从哪个点进行备份
change master to master_host=‘Master地址‘,
master_user=‘Tom‘,
master_password=‘密码‘,
master_log_file=‘mysql-bin.000002‘, #根据 show master status;
master_log_pos=3663; #根据 show master status;
六:执行同步开关
从库:
- start slave;
- 查看状态
show slave status;
正常状态:
Slave_IO_State: Waiting for master to send event
Master_Host: Master主机IP
Master_User: Tom
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes