一. 安裝包選擇:
mysql-5.0.19.tar.gz
二. 安裝環境:
主服務器: 192.168.0.201
從服務器: 192.168.0.00
三.主服務器配置:
Ø 建立用戶
grant replication slave on *.* to user001@192.168.0.200 identified by ‘111111′
Ø 編輯配置文件/etc/my.cnf
server-id = 1
log-bin=mysql-bin
binlog-do-db=test
binlog-ignore-db=mysql
注:
# grant replication slave on *.* to ‘用戶名’@'主機’ identified by ‘密碼’;
# binlog-do-db=需要備份的數據庫名,可寫多行
# binlog-ignore-db=不需要備份的數據庫名,可寫多行
# 可在B Slave上做連接測試: mysql -h 192.168.0.200 -u test -p
四.從服務器配置:
Ø 編輯/etc/my.cnf
server-id=2
server-id=2 記得是兩個???
log-bin=mysql-bin
master-host=192.168.0.201
master-user=user001
master-password=111111
master-port=3306
replicate-do-db=test
replicate-do-db=test1
# replicate-do-db=test 需要備份的數據庫名
# replicate-ignore-db=mysql 忽略的數據庫
# master-connect-retry=60 如果從服務器發現主服務器斷掉,重新連接的時間差(秒)
先手動同步一下主從服務器中要備份的數據庫,再重啟主,從服務器。
五.驗證是否配置正確:
# mysql> slave start;
# mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.201
Master_User: repluser1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000045
Read_Master_Log_Pos: 212
Relay_Log_File: sky-relay-bin.000054
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000045
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test,test1
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: 212
Relay_Log_Space: 235
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
1 row in set (0.00 sec)
確如如下行一致:
Waiting for master to send event
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
其他: ++主服務器上的相關命令
show master status
show slave hosts
show logs
show binlog events
purge logs to ‘log_name’
purge logs before ‘date’
reset master(老版本flush master)
set sql_log_bin=
++從服務器上的相關命令
slave start
slave stop
SLAVE STOP IO_THREAD //此線程把master段的日志寫到本地
SLAVE start IO_THREAD
SLAVE STOP SQL_THREAD //此線程把寫到本地的日志應用于數據庫
SLAVE start SQL_THREAD
reset slave
SET GLOBAL SQL_SLAVE_SKIP_COUNTER
load data from master
show slave status(SUPER,REPLICATION CLIENT)
CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,MASTER_USER=, MASTER_PASSWORD= //動態改變master信息
PURGE MASTER [before ‘date’] 刪除master端已同步過的日志
++產生了mysql-bin.00000x文件可以刪除
附一: mysql無法啟動:
# /usr/local/mysql//bin/mysqld_safe --user=mysql --log-error=err.txt
# more err.txt 根據里面的提示信息進行判斷分析
附二: 解決mysql“Access denied for user 'root'@'localhost'”
mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
修改root用戶的密碼:
# mysqladmin -uroot -p password 'newpassword' -
文章出處:http://www.diybl.com/course/6_system/linux/Linuxjs/2008622/127458.html
posted on 2009-04-15 14:02
周銳 閱讀(365)
評論(0) 編輯 收藏 所屬分類:
MySQL