您的位置:首頁 > 軟件資訊 > 編程技巧 > 數(shù)據(jù)庫
來源:北大青鳥飛迅校區(qū)|發(fā)布時間:2013-05-01 17:27:56
MYSQL實現(xiàn)雙機備份
虛擬機安裝的是CentOS5Mysql版本:5.1.31- log MySQL Community Server (GPL)1. 在主從服務器上分別安裝mysql
運行環(huán)境:
虛擬機安裝的是CentOS5
Mysql版本:5.1.31- log MySQL Community Server (GPL)
操作步驟:
1. 在主從服務器上分別安裝mysql
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
2. 配置主服務器
2.1 先登錄主機(59.57.251.56)
mysql>grant all on *.* to root@'%' identified by '1234'; -- 添加權限(賦予從機權限,有多臺叢機,就執(zhí)行多次)
mysql>GRANT All ON *.* TO 'backup'@'%' IDENTIFIED BY 'testbak';
mysql>flush privileges; -- 刷新權限
mysql>select host,user from user; --查看權限
2.2 打開主機A的my.cnf,輸入
server-id = 1 # 主機標示,整數(shù)
log_bin = /var/log/mysql/mysql-bin.log #確保此文件可寫
read-only =0 #主機,讀寫都可以
binlog-do-db =test #需要備份數(shù)據(jù),多個寫多行
binlog-ignore-db=mysql #不需要備份的數(shù)據(jù)庫,多個寫多行
2.3 打開從機B的my.cnf,輸入
server-id =2
log_bin =/var/log/mysql/mysql-bin.log
master-host =59.57.251.56
master-user =backup
master-pass =testbak
master-port =3306
master- connect-retry=60 #如果從服務器發(fā)現(xiàn)主服務器斷掉,重新連接的時間差(秒)
replicate-do-db =test #只復制某個庫
replicate-ignore-db=mysql #不復制某個庫
3. 主從數(shù)據(jù)同步
有多種方法:
1) 先mysqldump導出主機A的數(shù)據(jù)test為 test.sql
然后在從機B上建立數(shù)據(jù)庫test,mysql導入 test.sql到test庫中
2) 如果你想使用復制數(shù)據(jù)文件的方式來備份數(shù)據(jù)庫
只要在從服務器上的mysql命令行先鍵入slave stop;然后復制數(shù)據(jù)庫文件,復制好了,再在mysql命令行鍵入slave start;啟動從服務器,這樣就即備份了數(shù)據(jù)有保證了數(shù)據(jù)完整性,而且整個過程中主服務器的mysql無需停止。
4. 先重啟主機A的 mysql,再重啟從機B的mysql
招生熱線: 4008-0731-86 / 0731-82186801
學校地址: 長沙市天心區(qū)團結路6號
Copyright © 2006 | 湖南大計信息科技有限公司 版權所有
湘ICP備14017520號-3