- 論壇徽章:
- 0
|
環(huán)境: master:192.168.161.221 centos6.0 x86_64 mysql5.5.15 slave:192.168.161.227 centos6.0 x86_64 mysql5.5.15 注:master 的mysql版本最好與 slave 保持一致
master: 登錄master,新建一個測試庫: mysql> mysql -uroot -p
mysql> create database new;
創(chuàng)建一個同步用戶,限定只能在192.168.161.227登錄 mysql> grant replication slave on *.* to 'test1'@'192.168.161.227' identified by 'test1';
修改配置文件: vim /etc/my.cnf [mysqld] server_id=1 #主機(jī)標(biāo)識,整數(shù) binlog-do-db=new #需要備份的數(shù)據(jù)庫,多個寫多行 binlog-ignore-db=mysql #不需要備份的數(shù)據(jù)庫,多個寫多行 log-bin=mysql-bin #二進(jìn)制日志文件,確保此文件可寫 [msyqld_safe] log-error=/data/mysql/log/mysqld.log #錯誤日志文件
重啟服務(wù) /etc/init.d/mysqld restart
mysql -uroot -p
mysql> show master status;
slave: 登錄slave,新建一個測試庫: mysql> mysql -uroot -p
mysql> create database new;
修改配置文件: [mysqld] server_id=2 #從機(jī)標(biāo)識,整數(shù) log-bin=mysql-bin #二進(jìn)制日志文件,確保此文件可寫 replicate-do-db=new #要復(fù)制的數(shù)據(jù)庫,多個寫多行 replicate-ignore-db=mysql #不要復(fù)制的數(shù)據(jù)庫,多個寫多行
[msyqld_safe] log-error=/data/mysql/log/mysqld.log
重啟服務(wù) /etc/init.d/mysqld restart
mysql> mysql -uroot -p
mysql> slave stop;
//master_log_file,master_log_pos的值通過 master端的 show master status 獲得 mysql>
change master to
master_host='192.168.161.221',master_user='test1',master_password='test1',master_log_file='mysqlbin.000021',master_log_pos=107; mysql>slave start
測試: //在master端創(chuàng)建表,插入數(shù)據(jù) master端: mysql> use new;
mysql> create table xxx (id int(5),username varchar(20));
mysql> insert into xxx values(123,'hhhhh');
//slave端檢測,如能檢測到master端創(chuàng)建的表及插入的數(shù)據(jù),則說明配置成功。 slave端: msyql> use new;
mysql> show tables;
mysql> desc tables;
mysql> select * from xxx;
互為主從:
修改原slave端(192.168.161.227)配置: vim /etc/my.cnf [mysqld] binlog-do-db=new binlog-ignore-db=mysql
重啟服務(wù) /etc/init.d/mysqld restart
修改原master端(192.168.161.221)配置: vim /etc/my.cnf [mysqld] replicate-do-db=new replicate-ignore-db=mysql
重啟服務(wù) /etc/init.d/mysqld restart
mysql> mysql -uroot -p
mysql> slave stop;
//master_log_file,master_log_pos的值通過 show master status 獲得 mysql> change master to
master_host='192.168.161.227',master_user='test1',master_password='test1',master_log_file='mysql-bin.000022',master_log_pos=107; mysql>slave start
測試: //在master(原slave)端創(chuàng)建表,插入數(shù)據(jù) mysql> use new;
mysql> create table xxxx (id int(5),name varchar(20),price int(3));
mysql> insert into xxxx values(123,'aaaaa',1);
//slave(原master)端檢測,如能檢測到master(原master)端創(chuàng)建的表及插入的數(shù)據(jù),則說明配置
成功。 msyql> use new;
mysql> show tables;
mysql> desc tables;
mysql> select * from xxxx;
至此:mysql雙機(jī)熱備配置完成 |
|