美文网首页
Mariadb主从切换过程步骤

Mariadb主从切换过程步骤

作者: e652d1fb12eb | 来源:发表于2020-08-21 19:43 被阅读0次

1.查看slave数据库是否有数据更新

1)在master执行:show processlist;
显示Master has sent all binlog to slave; waiting for binlog to be updated
2)在slave执行:show processlist;
显示Slave has read all relay log; waiting for the slave I/O thread to update it
mysql> show slave status \G;
检查IO及SQL线程是否正常,如果为NO表明同步不一致,需要重新将slave同步保持主从数据一致。

SLAVE:

    stop slave;
    show slave status\G     ----->no,no
    reset slave all;
    systemctl stop mysql  --在主停止之後
    

查看slave是否只读模式:show variables like 'read_only';
只读模式需要修改my.cnf文件,注释read-only=1并重启mysql服务。

備份當前my.cnf并從主庫複製my.cnf,複製當前配置文件至主庫

mv /etc/my.cnf /etc/my.cnf.slave.old
scp root@xxx:/etc/my.cnf /etc/my.cnf  --注意server-id、binlog、relay-log、read-only參數
systemctl start mysql
grant replication slave on *.* to 'repl'@'xxx.xxx.xxx.xxx' identified by 'xxx' 
show master status\G; --查看binlog日誌位置和pos

MASTER:

reset master;
systemctl stop mysql
mv /etc/my.cnf /etc/my.cnf.master.old
scp /etc/my.cnf root@10.67.38.91:/etc/my.cnf
systemctl start mysql
change master to master_host='xxx.xxx.xxx.xxx',master_port=3306,master_user='repl',master_password='repl123',master_log_file='ostjombidb02-bin.000001',master_log_pos=000001;
start slave;
show slave status\G;

相关文章

网友评论

      本文标题:Mariadb主从切换过程步骤

      本文链接:https://www.haomeiwen.com/subject/zxepjktx.html