Ubuntu MySQL热备份安装

参考资料:

  http://www.cnblogs.com/wuhou/archive/2008/09/28/1301071.html

  http://www.hebaodans.com/2009/02/m-y-s-q-l-shu-ju-ku-de-tong-bu-wen-ti-shuang-ji-re-bei/

1.安装最新的Ubuntu Server版本,并更新系统。

2.安装MySQL Server:sudo apt-get instal mysql-server,然后设置管理员密码,去掉本地地址绑定,以便可以进行远程访问。

主:192.168.137.12

从:192.168.137.13

3.设置utf8字符集来支持中文,在主从服务器的配置文件/etc/mysql/my.cnf中加入:

 

[client]
default-character-set   = utf8

[mysqld]
default-character-set   = utf8

init_connect    = 'SET NAMES utf8;'

4.在服务器中启动备份。首先在主服务器在配置文件中添加下面的内容。其中s3(举个例子)为需要同步的数据库。

 

[mysqld]

log-bin         = mysql-bin
server-id       = 1
binlog-do-db    = s3

5.重新启动主数据库。

sudo service start mysql

6.连接到主数据库,并创建你需要同步的数据库,如果已经存在可以忽略这一步。

mysql –u root –p

create database s3;

7.在服务器中添加一个账号(sync)用于同步数据库,并赋予从备份的权限,重要。

grant replication slave on *.* to 'sync'@'%' identified by '12345'

8.记录s3数据库的日志文件名称和位置,用于从机备份开始的位置。

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000007 |      106 | s3           |                  |
+------------------+----------+--------------+------------------+

9.修改从机的配置文件。

 

[mysqld]
server-id       = 2
read-only
master-connect-retry     = 60
replicate-do-db = s3

10.重新启动从机,新建数据库(s3)或者从原来的数据库恢复数据库。并执行命令:

change master to MASTER_HOST='192.168.137.12', MASTER_USER='sync',MASTER_PASSWORD='12345',MASTER_LOG_FILE='mysql-bin.000007',MASTER_LOG_POS=106;

11.启动从机备份,并查看从机状态。

start slave;

show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.137.12
                  Master_User: sync
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000007
          Read_Master_Log_Pos: 106
               Relay_Log_File: S3-DB-SLAVE-1-relay-bin.000010
                Relay_Log_Pos: 251
        Relay_Master_Log_File: mysql-bin.000007
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: s3
          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: 106
              Relay_Log_Space: 559
              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:
1 row in set (0.00 sec)

    Slave_IO_Running: Yes 
    Slave_SQL_Running: Yes

表示工作正常,否者出现问题。出现问题重要的解决工具是查看日志记录。

cat /var/log/mysql/error.log

posted @ 2011-10-14 22:23  南桥一梦  阅读(589)  评论(0编辑  收藏  举报