时间:2021-07-01 10:21:17 帮助过:9人阅读
主从复制步骤
1:开启主库binlog功能
查看3306 是否开启
grep log-bin /etc/my.cnf
查看是否不一样
2:确保server-id 不同
grep server-id /etc/my.cnf
grep server-id /data/3307/my.cnf
3:主库授权 复制的用户rep
grant replication slave on *.* to rep@‘192.168.1.102‘ identified by ‘2017‘;
查看是否授权成功
4:锁表,查看binlog 位置点
先锁表 保证数据库一致
flush table with read lock;
show master status; 看看备份点
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000053 | 339 | | |
+------------------+----------+--------------+------------------+
5.新开窗口导出全备
mysqldump -uroot -p2017 -A -B --events -S /tmp/mysql.sock|gzip >/home/chaofu/rep_bak_$(date +%F).sql.gz
6: unlock table 解除锁表
从库:
1:确保server-id 不同
2:把主库的数据恢复到 从 库
gzip -d rep_bak.sql.gz
mysql -uroot -p -S /data/3307/mysql.sock < /home/chaofu/rep_bak_2017-11-21.sql
3:找位置点,配置master.info
CHANGE MASTER TO
MASTER_HOST=‘192.168.1.102‘,
MASTER_PORT=3306,
MASTER_USER=‘rep‘,
MASTER_PASSWORD=‘2017‘,
MASTER_LOG_FILE=‘mysql-bin.000053‘,
MASTER_LOG_POS=339;
find /data/3307/data -type -f -name "*.info"
4: 开启 备份开关
start slave;
show slave status \G;
从库两个线程
5:测试
主从复制原理图
本文出自 “9124122” 博客,请务必保留此出处http://9134122.blog.51cto.com/9124122/1983955
mysql主从复制
标签:mysql 主从复制