mysql 版本:4.1
環境介紹:主庫 192.168.0.205 從庫 192.168.0.206
1、主庫創建/etc/my.cnf,修改[mysqld]裡邊的鍵值增加
server-id=1
log-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; 顯示從庫正讀取哪一個主數據庫二進制日志