Mysql主從複製配置
一、測試環境
1.軟件環境
a)操作系統:
CentOS 6.5 X64
b)Mysql-Server:
mysql-server-5.1.73-3.el6_5.x86_64
2.網絡環境
每臺主機均有兩個網卡,其中一塊網卡與令一塊網卡直連;
a)Mater_DB:
i.Eth0:
192.168.99.11/24
ii.Eth1:
10.1.1.11/24
b)Slave_DB:
i.Eth0:
192.168.99.12/24
ii.Eth1:
10.1.1.12/24
3.
二、相關解釋
三、實驗過程
a)Master_DB
i.安裝Mysql-server (略)
ii.配置Mysql-Server
1.修改Mysql下root用戶密碼;
2.創建一個用於測試的數據庫
3.修改配置文件
a)vim /etc/my.cnf
增加如下段:
[mysqld]
server-id=1 #指定服務ID
log-bin=log #開啓log
binlog_do_db=luoyangbo #選擇需要同步的數據庫
binlog_ignore_db=test,mysql #選擇不需要同步的數據庫
b)重啓數據庫
b)Slave_DB
1.修改Mysql下root用戶密碼;
2.創建一個MaterDB上需要同步的數據庫一樣名稱的測試的數據庫
3.修改配置文件
a)vim /etc/my.cnf
增加如下段:
[mysqld]
server-id=2 #服務器ID
master-host=10.1.1.11 #主服務器地址
master-user=slave01 #連接主服務器的Mysql用戶名 master-password=7490283 #連接主服務器的Mysql密碼
master-port=3306 #連接主服務器的端口
master-connect-retry=20 #如果連接失敗,重試的時間
replicate-do-db=luoyangbo #同步的數據庫名稱
replicate-ignore-db=mysql,test #不同步的數據庫名稱
b)重啓數據庫
4.測試Mysql主從配置
a)Master DB
i.創建一個表,並插入行數據;
Create tables test(id int,name char(10));
Insert into test values(1,hello);
b)Slave DB
i.檢索test表是否同步
show tables;
select * fromtest;