您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“MYSQL主從復(fù)制的搭建方式”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“MYSQL主從復(fù)制的搭建方式”吧!
前言:MYSQL的主從復(fù)制的原理跟MYSQL的主主復(fù)制的原理其實(shí)是一樣的,但是從數(shù)據(jù)庫不能用于寫操作,所以在配置的過程中會(huì)存在部分參數(shù)配置的一些不一樣的地方;
主主和主從復(fù)制的架構(gòu)圖
主從復(fù)制的具體配置步驟如下:
一、主數(shù)據(jù)庫參數(shù)的配置
log-bin=mysql-bin # binary logging format - mixed recommended binlog_format=mixed //主從復(fù)制模式,混合模式(MBR)默認(rèn)的 binlog_cache_size=4M //設(shè)置binlog緩存大小 max_binlog_size=300M //設(shè)置binlog文件最大體積 replicate_do_db=retail |
二、在主數(shù)據(jù)庫上面創(chuàng)建通訊用戶
腳本如下:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'server01'@'%' IDENTIFIED BY 'server01'; |
三、進(jìn)行主數(shù)據(jù)庫的備份
備份Master上的數(shù)據(jù),首先執(zhí)行鎖表操作,如下SQL語句:
mysql>FLUSH TABLES WITH READ LOCK; //先鎖定數(shù)據(jù)庫,等恢復(fù)完成后,再解鎖 Query OK, 0 rows affected (0.00 sec) mysql> reset master; Query OK, 0 rows affected (0.00 sec) 不要退出這個(gè)終端,否則這個(gè)鎖就失效了;在不退出終端的情況,再開一個(gè)終端直接打包壓縮數(shù)據(jù)文件或使用mysqldump工具來導(dǎo)出數(shù)據(jù)。 # mysqldump -uroot -p retail > /tmp/retail.sql mysql> show master status; //查看主服務(wù)器binlog和Postion *************************** 1. row ************************************** File: mysql-bin.000001 Position: 2424 Binlog_Do_DB: Binlog_Ignore_DB: 1 row in set (0.00 sec) |
三、設(shè)置SLAVE的參數(shù)文件
#binlog_format=mixed # required unique id between 1 and 2^32 - 1 # defaults to 1 if master-host is not set # but will not function as a master if omitted server-id= 3 //跟master區(qū)分開來 read_only=1 replicate_do_db= retail |
四、在SLAVE數(shù)據(jù)庫上面進(jìn)行恢復(fù)
創(chuàng)建retail數(shù)據(jù) mysql> create database retail
進(jìn)行數(shù)據(jù)的導(dǎo)入 mysql> SOURCE /tmp/retail.sql |
五、在SLAVE上面設(shè)置連接Master,并啟動(dòng)SLAVE
mysql> CHANGE MASTER TO MASTER_HOST='192.168.47.149',MASTER_USER='server',MASTER_PASSWORD='server', MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=2424;
mysql> SLAVE START //啟動(dòng)SLAVE服務(wù)
mysql> SHOW SLAVE STATUS\G; //檢查slave的連接情況 mysql> SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.47.149 Master_User: server Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 2424 Relay_Log_File: mysql03-relay-bin.000002 Relay_Log_Pos: 666 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 2424 Relay_Log_Space: 824 Until_Condition: None |
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
以上兩個(gè)值,都為YES的時(shí)候,說明主從配置已經(jīng)成功了。
到此,相信大家對(duì)“MYSQL主從復(fù)制的搭建方式”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。