centos mysql双机备份_[原创]CentOS下Mysql双机互为备份

一、环境:

1.安装Centos-6.5-x64位系统的机器两台:

host1:192.168.2.3

host2:192.168.2.4  (互相能ping通)

2.安装Mysql。 命令:Yum install mysql-*

二、配置:

1、启动mysql。命令:service mysqld start

设置mysql的root密码。命令:mysqladmin –u root password 回车后输入要设置的密码即可。

2、创建数据库test1和表test1。

Create database test1;

Use test1;

Create table test1(id int(5),name varchar(10));

3.配置mysql配置文件:/etc/my.cnf.配置内容如下:

Host1:

[mysqld]

Server-id=1

Log-bin=bin-log

Binlog-ignore-db=mysql,test,infromation_schema

Binlog-do-db=test1

Master-host=192.168.2.4

Master-port=3306

Master-user=root

Master-password=111

Master-retry-count=999

Master-connect-retry=60

Host2:

[mysqld]

Server-id=2

Log-bin=bin-log

Binlog-ignore-db=mysql,test,infromation_schema

Binlog-do-db=test1

Master-host=192.168.2.3

Master-port=3306

Master-user=root

Master-password=110

Master-retry-count=999

Master-connect-retry=60

4.重启mysql。命令:service mysqld restart

1.如果不能启动服务,则仔细检查配置文件是否写错,检查无误后关闭防火墙。命令:service iptables stop(chkconfig iptables off)。

2.Host1使用mysql –h host2.IP –u root –p 登录host2的mysql看是否成功

3.Host2使用mysql –h host1.IP –u root –p 登录host1的mysql看是否成功

成功说明双机上的mysql服务和访问正常。

5.配置授权。

Host1:        mysql>grant replivation slave on *.* to ‘root’@‘192.168.2.4’ identified by ‘host1中mysql的root密码’;

Host2:        mysql>grant replivation slave on *.* to ‘root’@‘192.168.2.3’ identified by ‘host2中mysql的root密码’;

6.host1,host2分别登录本机mysql。Mysql –u root –p回车输入密码。

查看master和slave状态:

命令:show master status\G;

Show slave status\G;

Host1:

dfe31a4f80e1bab40ae8f00368812e01.png

Host2:

2c13ce1a121d38486102cf667f0866ce.png

结果如上图所示,slave_IO_Running和slave_SQLRunning都为YES则表示配置成功。

如果出现slave_IO_Running:NO; Last_IO_Error: Got fatal error 1236 from master when  reading data from binary log:‘Client requested master to start  replication from impossible position‘

的错误,则是因为主机日志文件的配置问题。

解决:使用show master status\G;查看master的file和position的值,然后用一下命令设置:

mysql> stop slave;

mysql> change master to master_log_file=‘file值‘,master_log_pos=position值;

mysql> start slave;

7.测试:

分别在host1和host2的mysql-jhk-test1表中插入不同数据来测试。

4d7dd3a5d478054f26fb74fe0679ba7d.png

结果显示双机实现互为热备份。删除数据和表测试(略)

原文:http://www.cnblogs.com/wsjhk/p/4589416.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值