随笔-62  评论-29  文章-0  trackbacks-0

 

测试环境:

RedHat ES 4 update 3

MYSQL 5.0.15

MYSQL数据同步备份

A服务器: 150.236.66.160 主服务器master

B服务器: 150.236.66.172  副服务器slave

1A服务器设置上修改/etc/my.cnf

[mysqld]区段内加入参数

#(要同步的数据库)

binlog_do_db = gdcu

2:设置能够访问A服务器用户,该用户能够做同步操作

#mysql –u root –p

mysql>GRANT FILE ON *.* TO backup@150.236.66.172 IDENTIFIED BY 'orient5757';

      grant replication slave,reload,super on *.* to backup@150.236.66.172 identified by 'orient5757'

mysql>FLUSH PRIVILEGES;

3B服务器设置

设定/etc/my.cnf

[mysqld]区段加入

#(如果还有slave用户,他们的ID也随之增加,如server-id=3

server-id = 2  

master-host = 150.236.66.160

master-user = backup

master-password = orient5757

replicate-do-db = gdcu

master-port=3306

master-connect-retry = 60

log-bin=mysql-bin

4:在 master 上执行命令显示 master 状态:

mysql> SHOW MASTER STATUS;

看到信息类似如下:

+—————+———-+————–+——————+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+—————+———-+————–+——————+
| mysql-bin.003 | 73       | gdcu       | manual,mysql     |
+—————+———-+————–+——————+

记下 LOG FILE Position

5、把 master 数据库拷贝到 slave,在slave上执行如下语句,把各个选项的值替换成真实值:实质是设置slave数据从master数据库读取数据库操作的事务。

mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST=’
150.236.66.160′,MASTER_USER=’bakcup,MASTER_PASSWORD=’orient5757,MASTER_LOG_FILE=’mysql-bin.000003′,MASTER_LOG_POS=73;


6
、启动 slave 线程,并查看 slave 状态:

mysql> START SLAVE;
mysql> SHOW SLAVE STATUS;

测试结果:

master数据库操作,基本上数据是瞬间同步到slave上。

如果slave数据库未运行,master 数据库发生变化,在slave开始运行的时候,会把发生变化的数据同步过来。


双向备份:
主机
#add for master backup
#log-bin=mysql-bin
server-id=1
binlog_do_db = gdcu
#binlog_ignore_db = mysql,information_schema

 


#server-id = 2
#拢篓脠鹿没slave脫禄搂拢卢脣脙碌脛D也脣之脭录樱卢脠server-id=3拢漏
master-host = 192.168.1.6
master-user = root
master-password = orient5757
replicate-do-db = gdcu
#replicate-do-db = database2
#log-warnings
master-port=3306
master-connect-retry = 60
#bin-log =
log-bin=mysql-bin


备份机:
server-id = 2
#(如果还有slave用户,他们的ID也随之增加,如server-id=3)
master-host = 192.168.1.5
master-user = root
master-password = orient5757
replicate-do-db = gdcu
#replicate-do-db = database2
#log-warnings
master-port=3306
master-connect-retry = 60
#bin-log =
log-bin=mysql-bin

#server-id=1
binlog_do_db = gdcu



在 '192.168.1.6'上操作

stop slave;
CHANGE MASTER TO MASTER_HOST='192.168.1.5',MASTER_USER='root',MASTER_PASSWORD='orient5757',MASTER_LOG_FILE='mysql-bin.000023',MASTER_LOG_POS=98;

在 '192.168.1.5上操作

stop slave;


CHANGE MASTER TO MASTER_HOST='192.168.1.6',MASTER_USER='root',MASTER_PASSWORD='orient5757',MASTER_LOG_FILE='mysql-bin.000054',MASTER_LOG_POS=98;



posted on 2008-11-06 18:29 阅读(720) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: