MySQL 版本:4.1
環境介紹:主庫 192.168.0.205 從庫 192.168.0.206
1、主庫創建/etc/my.cnf,修改[MySQLd]裡邊的鍵值增加
server-id=1log-bin=binlog_name
2、主庫增加用戶,用於從庫讀取主庫日志。
grant replication slave,reload,super on *.* to ’slave’@’192.168.0.206’ identifIEd by ’123456’
3、從庫連接主庫進行測試。
/opt/mysql/bin/MySQL -u slave -p -h 192.168.0.205
4、停從庫,修改從庫/etc/my.cnf,增加選項:
[MySQLd]
server-id=2
master-host=192.168.0.205
master-user=slave
master-passWord=123456
5、啟動從庫,進行主從庫數據同步
/opt/mysql/share/mysql/MySQL start/opt/mysql/bin/MySQL -u root -p
MySQL>load data from master;
6、進行測試:
主庫創建表,
MySQL>create database sampdb;
MySQL>create table new (name char(20),phone char(20));
MySQL>insert into new (’abc,’0532555555’);
打開從庫,察看:
/opt/mysql/bin/MySQL -u root -p
MySQL>show database;
MySQL
sampdb
test
MySQL>use sampdb;
MySQL>show tables;
new
說明主從數據庫創建成功。
7、主從數據庫相關命令:
slave stop; slave start ; 開始停止從數據庫。show slave status\G; 顯示從庫正讀取哪一個主數據庫二進制日志