mysql主从如果住挂了_mysql 主从复制

本文介绍了如何设置MySQL主从复制,包括在主服务器上配置复制用户、修改server id、开启binary logging,以及在从服务器上导入备份并设置复制。详细步骤包括完全备份、解锁表、导入数据和启动复制。同时,文章还阐述了主从切换的过程,确保在主服务器故障时能够平滑过渡,以及如何将原主服务器恢复为从服务器。
摘要由CSDN通过智能技术生成

基础知识:

b9a2493074b50bd0d1c3ca84924f927f.png

需求:

56fc1b4d80c693d41a8967a680ee5907.png

最初只有主数据库,这样即使有数据备份,对业务保证也不够高(业务不大,不需要做主主)。所以新增一台数据库备用服务器,做主从复制。

准备:

在master数据库服务器的操作添加用于复制的用户

grant replication client,replication slave on *.* to 'angus'@'%.%.%.%' identified by 'password';

修改server  id (只要主从server id不一样就行,可以再从服务器该。)

开启binary logging(一般都开启过)

在slaver数据库服务器的操作

修改server id

开启relay-log

开启binary logging(主从切换 做准备)

操作:

1,在从服务器上配置好数据库,最后和主数据库是一个版本。

2,sed -i '/^server-id/s#1#2#g' /etc/my.cnf

3,开启relay-log 在/etc/my.cnf 的[mysqld]区域添加下面代码

relay-log=relay-bin

relay-log=relay-bin.index

sed -i '/^server-id/a\relay-log=relay-bin\nrelay-log=relay-bin.index' /etc/my.cnf

4,对主数据进行一次完全备份

[root@localhost ~]# mysql -uroot    -p

Enter password:

Welcome to the MySQL monitor.    Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.1.66 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> flush tables with read lock;

Que

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值