配置环境:

myslq 5.5.3 + ubuntu server 12.04

一、配置MySQL主服务器(192.168.0.1)

1.增加一个账号专门用于同步

1
mysql>grant replication slave on *.* to user@192.168.0.2 identified by '123456';

2.接下来备份数据,首先执行如下SQL语句:

1
2
3
mysql>flush tables with read lock;
     
mysql>mysqldump -u root -p esmartgo > /home/esmartgo.sql

3.然后将这些数据拷贝到mysql从服务器(192.168.0.2)上,恢复数据,设置好正确的权限及属主等;之后,执行"UNLOCK TABLES"语句来释放锁。

1
mysql>unlock tables;

4.修改mysql配置文件

1
vi /etc/my.cnf  

5.编辑配置文件,在[mysqld]部分添加下面内容

1
2
3
4
server-id=1  #设置服务器id,为1表示主服务器,注意:如果原来的配置文件中已经有这一行,就不用再添加了。
log_bin=mysql-bin #启动MySQ二进制日志系统,注意:如果原来的配置文件中已经有这一行,就不用再添加了。
binlog-do-db=esmartgo #需要同步的数据库名,如果有多个数据库,可重复此参数,每个数据库一行
binlog-ignore-db=mysql  #不同步mysql系统数据库

6.重启mysql

1
service mysqld restart #重启MySQL

7.进入mysql控制台

1
mysql -u root -p  #进入mysql控制台

8.查看主服务器

1
show master status;

显示如下信息

1
2
3
4
5
6
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |    40538 | esmartgo     |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

注意:这里记住File的值:mysql-bin.000001和Position的值:40538,后面会用到。

二、配置MySQL从服务器(192.168.0.2)

1.修改mysql配置文件

vi /etc/my.cnf

2.编辑配置文件,在[mysqld]部分添加下面内容

1
2
3
4
server-id=2  #配置文件中已经有一行server-id=1,修改其值为2,表示为从数据库。
log_bin=mysql-bin #启动MySQ二进制日志系统,注意:如果原来的配置文件中已经有这一行,就不用再添加了。
replicate-do-db=esmartgo #需要同步的数据库名,如果有多个数据库,可重复此参数,每个数据库一行
replicate-ignore-db=mysql  #不同步mysql系统数据库

3.重启mysql

service mysqld restart #重启MySQL

4.进入mysql控制台

mysql -u root -p  #进入mysql控制台

5.停止slave同步进程

1
slave stop;  #停止slave同步进程

6.修改master配置属性

1
2
3
4
5
6
7
8
9
10
11
12
13
change master to
    
master_host='192.168.0.1',
    
master_port = 3306,
    
master_user='user',
    
master_password='123456',
    
master_log_file='mysql-bin.000001',
    
master_log_pos=40358;

7.查看slave同步信息

1
show slave status\G

8.显示结果( Slave_IO_Running: Yes Slave_SQL_Running: Yes说明已经同步成功)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 101.227.252.54
                  Master_User: user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 40538
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 36464
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: esmartgo
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 40538
              Relay_Log_Space: 36621
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
1 row in set (0.00 sec)

ubuntu上的mysql数据库双机备份设置的更多相关文章

  1. Ubuntu上更改MySQL数据库数据存储目录

    之前写过一篇博客"MySQL更改数据库数据存储目录",当时的测试环境是RHEL和CentOS,谁想最近在Ubuntu下面更改MySQL数据库数据存储目录时遇到了之前未遇到的问题,之 ...

  2. Windows远程连接Ubuntu上的MySQL数据库

    原因:mysql安装好后,默认监听3306端口,并且只允许localhost访问,只允许root用户在localhost上登录.   我的环境:                 Ubuntu16.04 ...

  3. navicate远程访问ubuntu上的mysql数据库

    安装mysql 首先检查系统中是否已经安装了MySQL,在终端里面输入: sudo netstat -tap | grep mysql 如上所示就是正确安装并启动,启动命令为 sudo /etc/in ...

  4. CentOS 7上更改MySQL数据库存储目录浅析

      个人之前总结过两篇文章"MySQL更改数据库数据存储目录"和"Ubuntu上更改MySQL数据库数据存储目录",都是在工作中遇到相关案例后的一个简单总结.当 ...

  5. MySQL数据库双机热备------主-主备份配置

    MySQL数据库双机热备------主-主备份配置 实验环境: 主1数据库 192.168.1.1 centos6.5 x86_64 +MySQL5.5.35 主2数据库192.168.1.2  Wi ...

  6. [mysql]设置Ubuntu上的MySQL可以远程访问

    今天在win10上用django连接安装在Ubuntu上的MySQL上,始终提示错误(can not connect mysql),但是在Ubuntu上访问是没有问题的.于是开始查找原因: 1. 33 ...

  7. Ubuntu Server下MySql数据库备份脚本代码

    明: 我这里要把MySql数据库存放目录/var/lib/mysql下面的pw85数据库备份到/home/mysql_data里面,并且保存为mysqldata_bak_2012_04_11.tar. ...

  8. 在linux上安装MySQL数据库,并简单设置用户密码,登录MySQL

    在新装的Centos系统上安装MySQL数据库. <p><a href="http://www.cnblogs.com/tijun/">提君博客原创< ...

  9. 在Ubuntu中建立MySQL数据库

    最近在做一个关于云计算安全系统的项目,需要用到MySQL数据库,现在把建立数据库的步骤记录下来. 一.用命令在Ubuntu上安装MySQL # sudo apt-get update # sudo a ...

随机推荐

  1. 如何利用 MembershipUser 更改密码

    如何利用 MembershipUser 更改密码 作者: vkvi 来源:千一网络 (原创) 时间: 2009-3-11   完美集成.增强 KindEditor HTML 编辑器 在 ASP.NET ...

  2. ios 中Category类别(扩展类)小结

    类别 类别是一种为现有的类添加新方法的方式.利用Objective-C的动态运行时(runtime)分配机制,可以为现有的类添加新方法,这种为现有的类添加新方法的方式称为类别catagory,他可以为 ...

  3. startssl证书firefox支持配置

    解决Firefox不信任StartSSL证书问题 wget http://cert.startssl.com/certs/ca.pem wget http://cert.startssl.com/ce ...

  4. HttpServletResponse对象(一)

    web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象,和代表响应的response对象. request和response对象既然代表请求和响应,那么我 ...

  5. 【Python爬虫实战--3】html写正则表达式

    以下是要爬虫的html内容: <div class="article block untagged mb15" id='qiushi_tag_113452216'> & ...

  6. 关于oracle数据库(6)约束

    约束类型 1.主键primary key(一般是一个表的标志,所以一个表只能有一个主键:主键不能为空,不能重复) 2.唯一键unique(不能重复) 3.外键foreign key 4.检查约束che ...

  7. C语言_函数【转】

    引用地址:http://baike.baidu.com/link?url=U9h6MccLYX2w5uyVOqIFd3eps5gR2FZA10jYRLRnc66Ff_F5ZrmXGKA12DT-_2x ...

  8. C++中复制构造函数和赋值操作符

    先看一个例子: 定义了一个类:

  9. 为什么要重写equals和hashCode

    1.重写equals方法时需要重写hashCode方法,主要是针对Map.Set等集合类型的使用: a: Map.Set等集合类型存放的对象必须是唯一的: b: 集合类判断两个对象是否相等,是先判断e ...

  10. CentOS7 PostgreSQL 安装

    PostgreSQL安装 安装使用yum安装 (找源 http://yum.postgresql.org/) yum install https://download.postgresql.org/p ...