mysql主從復(fù)制(默認(rèn)異步)

一主一從?本文用的是?yum install -y mariadb ?安裝配置MySQL復(fù)制基本步驟:一、**master**1、啟用二進(jìn)制日子,選擇一個唯一server-id?
2、創(chuàng)建具有復(fù)制權(quán)限的用戶?
進(jìn)入mysql?
MariaDB [(none)]>GRANT REPLICATION SLAVE ON . TO 'mysql141'@'192.168.137.153' IDENTIFIED BY '123456'; ?#創(chuàng)建用戶mysql141 ip地址指向從服務(wù)器 ?密碼為123456?
3.測試創(chuàng)建的用戶連接性?
退出mysql,然后輸入以下命令看是否能進(jìn)入,密碼123456?
[root@localhost ~]#mysql -umysql141 -p?
如果報錯:mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)?
解決方法:vi /etc/my.cnf ??添加 ?skip-grant-tables?
二、slave?
1、啟用中繼日志,選擇一個唯一的server-id?
relay-log = relay-log?
server-id =?
2、連接至主服務(wù)器,并開始復(fù)制數(shù)據(jù);?
進(jìn)入MySQL:?
mysql> CHANGE MASTER TO master_host = '主服務(wù)器',master_user = 'mysql141',master_password = '123456',master_log_file = 'mysql-log.000010',master_log_pos = 480;?
mysql> start slave ??#開啟下面兩個狀態(tài)為YES?
mysql>SHOW SLAVE STATUS \G; #查看狀態(tài)?
Slave_IO_Running: Yes?
Slave_SQL_Running: Yes?
當(dāng)看到Slave_IO_State:Waiting for master ot send event?、Slave_IO_Running: YES、Slave_SQL_Running: YES才表明狀態(tài)正常。?
注意:?
master_log_file = 'mysql-log.000010' #在主服務(wù)器用show master status;查看?
master_log_pos = 480 ????????????????#在主服務(wù)器用show master status;查看?
三、測試主從復(fù)制是否成功?
在主服務(wù)器上創(chuàng)建數(shù)據(jù)庫?
SHOW DATABASES; #查看當(dāng)前的數(shù)據(jù)庫?
CREATE DATABASE haha; ?#創(chuàng)建數(shù)據(jù)庫haha?
在從服務(wù)器上查看?
SHOW DATABASES; #查看數(shù)據(jù)庫是否有haha這個數(shù)據(jù)庫?
如果有haha這個庫,說明你已經(jīng)成功了!
?了解更多網(wǎng)絡(luò)知識關(guān)注:http://www.vecloud.com/