Mysql 主从复制,不停机添加新从节点 1、主库创建账号: show master status; GRANT REPLICATioN SLAVE ON . to 'reader'@'%' identif
Mysql 主从复制,不停机添加新从节点
1、主库创建账号:
show master status;
GRANT REPLICATioN SLAVE ON . to 'reader'@'%' identified by 'readerpwd';
flush privilegs
2、从库配置
开启binlog
log-bin=/var/lib/mysql/mysql-bin
server-id=3 //参照原从库配置+1
3、备份主库
mysqldump -uroot -p123 --routines --single_transaction --master-data=2 --databases testdb > testdb.sql
参数说明:
4、从库创建数据库,并导入数据
将dump的数据拷贝到从库后开始导数据
mysql> grant all pricileges on *.* to testdb.* identified by 'testdb';
mysql> create database testdb;
mysql> source /tmp/testdb.sql
5、查看备份文件的binlog 和 pos值
# head -25 testdb.sql
root@mysql20151:/tmp# head -25 /tmp/0907.sql
-- MySQL dump 10.13 Distrib 5.5.46, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: vphotos
-- ------------------------------------------------------
-- Server version 5.5.46-0ubuntu0.14.04.2-log
;
;
;
;
;
;
;
;
;
;
--
-- Position to start replication or point-in-time recovery from
--
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.003789', MASTER_LOG_POS=49778941;
可以看到 MASTER_LOG_FILE='mysql-bin.003789', MASTER_LOG_POS=49778941;
6、启动从库
mysql> change master to master_host='10.*.*.*',master_user='reader',master_passWord='readerpwd',master_log_file='mysql-bin.003789',master_log_pos=49778941;
// 验证从库状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.3.16.7
Master_User: slave02
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.003791
Read_Master_Log_Pos: 99002276
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.003789
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
..................
注:看到IO和SQL线程均为YES,说明主从配置成功。
参考:
https://yq.aliyun.com/articles/38826
--结束END--
本文标题: MYSQL 主从添加新从库
本文链接: https://lsjlt.com/news/52637.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0