標籤:service 伺服器 master 資料庫
環境準備:
匹配固定ip地址 、能夠正常通訊service iptables stopsetenforce 0service mysql start從資料庫伺服器上的初始資料一定要和主要資料庫伺服器上的值一致 server_uuid值不能相同vim /var/lib/mysql/auto.cnf master //MySQL 192.168.1.1 salve //從MySQL 192.168.1.2
一、配置主要資料庫伺服器:192.168.1.1
1、vim /etc/my.cnf[mysqld]server_id=1 log-bin=log:wqservice mysql restart【cat /var/log/mysqld.log 錯誤記錄檔】2、授權一個使用者可以從 slave資料庫伺服器串連自己,串連後有拷貝資料的許可權。mysql -hlocalhost -uroot -p999mysql>grant replication slave on *.* to [email protected]"192.168.1.2" identified by "123";mysql> show master status; //查看主要資料庫伺服器的狀態mysql>quit;
3. 配置從資料庫伺服器:192.168.1.2
mysql -h192.168.1.1 -uslaveuser -p123 //驗證授權mysql>quit;vim /etc/my.cnf[mysqld]server_id=200 :wqservice mysql start[[email protected] ~]# mysql -uroot -p999(從)mysql> change master to -> master_host="192.168.1.1", -> master_user="slaveuser", -> master_password="123", -> master_log_file="log.000001", //來自master status -> master_log_pos=120; mysql> start slave;mysql>show slave status\G; //查看從資料庫伺服器的狀態 Slave_IO_Running: YesSlave_SQL_Running: Yes //這個倆個都為yes說明配置正確
二、測試主從同步?
mysql -uroot -p999 // (登陸主要資料庫)mysql> create database db1;mysql> create table db1.a(id int);mysql> insert into db1.a values(100);mysql -uroot -p999 // (登陸從資料庫)select * from db1000.a;ls /var/lib/mysql/ //查看從資料庫的目錄master.infolocalhost-relay-bin.index localhost-relay-bin.000001relay-log.info
MySQL主從同步