標籤:roo pre set star res mct cto ast pos
準備:兩台MySQL資料庫
一、配置主要資料庫
1、添加使用者
mysql> grant replication slave on *.* \
-> to
-> [email protected]"192.168.4.12" 授權使用者/ip
-> identified by "111111"; 密碼
2、啟動binlog日誌
[mysqld]
server_id=1
log-bin=master1
binlog_format="mixed"
3、重起資料庫服務
[[email protected] ~]#systemctl restart mysqld
4 查看日誌資訊
mysql> show master status;
二、配置從資料庫
1、驗證主庫提供的授權使用者
[[email protected] ~]# mysql -h192.168.4.11 -uslaveuser -p111111
2、修改設定檔 指定設定檔
[mysqld]
server_id=2
log-bin=master2
3、指定主庫資訊
mysql> change master to master_host="192.168.4.11",
master_user="slaveuser",
master_password="111111",
master_log_file="master1.000001",
master_log_pos=154;
4、開啟服務
mysql> start slave;
關閉服務
mysql> stop slave;
刪除服務
mysql> reset slave;
5、查看
mysql> show slave status\G;
Slave_IO_Running: Yes IO線程已運行
Slave_SQL_Running: YesSQL線程已運行
從資料庫目錄下多的檔案
[[email protected] ~]#cat /var/lib/mysql/*
master.info 串連主伺服器資訊
relay-log.info 中斷日誌資訊
主機名稱-relay-bin.xxxxxx 中斷日誌
bogon-realy-bin.index 中斷日誌索引檔案
三、測試主從同步配置
1、 主伺服器上建立庫
mysql> create database ctoll;
2、 從伺服器也能查看
【一主多從】
mysql> grant replication slave on *.*
to
[email protected]"%" % --->多台主機
identified by "111111";
MySQL主從同步基本配置