一、环境:

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.host1host2分别登录本机mysqlMysql –u root –p 回车输入密码。

查看master和slave状态:

命令:show master status\G;

Show slave status\G;

    Host1:

       

    Host2:

      

结果如上图所示,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表中插入不同数据来测试。

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

[原创]CentOS下Mysql双机互为备份的更多相关文章

  1. [原创]CentOS下Mysql的日志回滚

    一.    环境: a)        Centos-6.5-x64位操作系统. b)        安装mysql.命令:yum install mysql* 二.    配置 a)        ...

  2. CentOS 下 MySQL DateBasic 抢救

    CentOS 下 MySQL DateBasic 抢救 强 Kill 数据库进程. 分析问题:确定报错内容 报错信息:The server quit without updating PID file ...

  3. CentOS下MySQL 5.7编译安装

    CentOS下MySQL 5.7编译安装   文章目录 安装依赖包 下载相应源码包 添加mysql用户 预编译 编译安装 启动脚本,设置开机自启动 /etc/my.cnf,仅供参考 初始化数据库 设置 ...

  4. CentOS下mysql常用命令

    CentOS下mysql常用命令   1.开启和关闭 1.1.开启 service mysql start 1.2.关闭 service mysql stop 1.3.重启 service mysql ...

  5. CentOS下Mysql安装教程

    CentOS下Mysql安装教程 本人学习Linux时使用的是CentOs5.5版本,在该环境中,Mysql的安装方法有很多种,下面我只讲我这次成功了的方法,作为一个记录,供大家参考,同时给自己做一个 ...

  6. CentOS 下mysql ERROR&n…

    CentOS 下mysql ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO) 描述:在操作数据库时会出 ...

  7. CentOS 下 MySQL 5.6 基于 RPM 的下载、安装、配置

    CentOS 下 MySQL 5.6 基于 RPM 的下载.安装.配置 系统: CentOS 7 x86_64 MySQL 版本: 5.6.40 安装方式: RPM 下载 下载地址 操作系统 选择 R ...

  8. CentOS系统MySQL双机热备配置

    1  概述 在集成项目中需要应对不同环境下的安装配置,主流操作系统大致可以分为三种:Linux.Windows以及UNIX.其中Linux备受青睐的主要原因有两个: 首先,Linux作为自由软件有两个 ...

  9. linux下 mysql数据库的备份和还原

    1.备份 [root@CentOS ~]# mysqldump -u root -p mysql > ~/mysql.sql #把数据库mysql备份到家目录下命名为mysql.sql Ente ...

随机推荐

  1. 在my.ini文件中配置mysql统一字符集

    测试的mysql版本为:5.7.14 查看mysql字符集命令: show variables like 'character_set_%'; 以下是在my.ini文件中配置mysql统一字符集参数: ...

  2. Struts2中there is no action mapped for acion name (/XXXXX)

    这里的问题出在配置struts.xml中,去掉配置中 namespace="/"属性 即可解决.不同的调用action的方式对namespace="/"属性有的 ...

  3. Spark源码分析之分区器的作用

    最近因为手抖,在Spark中给自己挖了一个数据倾斜的坑.为了解决这个问题,顺便研究了下Spark分区器的原理,趁着周末加班总结一下~ 先说说数据倾斜 数据倾斜是指Spark中的RDD在计算的时候,每个 ...

  4. Filter execution threw an exception 错误

    Filter execution threw an exception 错误,我在web.xml中配置了一个filter用spring来解决懒加载的问题,为什么就会包这个错 java.lang.NoS ...

  5. node express安装

    我们现在全局安装只需要安装这个命令行工具就可以,指令如下: npm install -g express-generator 这时我们就着手安装express框架,指令如下: express blog ...

  6. golang环境

    Golang是谷歌开发的一款开源性语言,暂时比较方便的IDE有Inteillj Idea.LiteIDE.Eclipse(Golipse)等,使用起来比较方便的IDE:LiteIDE和Inteillj ...

  7. Vue 事件驱动和依赖追踪

    之前关于 Vue 数据绑定原理的一点分析,最近需要回顾,就顺便发到随笔上了 在之前实现一个自己的Mvvm中,用 setter 来观测model,将界面上所有的 viewModel 绑定到 model ...

  8. Python科学计算—numpy模块总结(1)

    作为一个本科学数学专业,目前研究非线性物理领域的研究僧.用什么软件进行纯科学计算好,Fortran永远是第一位的:matlab虽然很强大,可以很容易的处理大量的大矩阵,但是求解我们的模型(有时可能是几 ...

  9. 修改linux系统时间和同步

    date 查看当前时间 date -s 15:14:13 修改时间 cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 修改时区 yes cront ...

  10. C#是否该支持“try/catch/else”语法

    以前用过一段时间Python,里面有个try/catch/else语法,我觉得挺好用,这个语法形如下: try: print('try...') r = 10 / int('2') print('re ...