02- MySQL主從複製(MySQL剛安裝完成)

來源:互聯網
上載者:User

標籤:mysql

作業系統:Red Hat Enterprise Linux 6.6 x86_64


伺服器資訊:

master.mysql.whh.org     192.168.255.1

slave.mysql.whh.org      192.168.255.2


master伺服器配置:

1- 編輯/etc/my.cnf檔案,設定伺服器server-id為1,id號建議使用伺服器ip地址最後一位。

2- 重啟服務,service mysqld restart。

3- 設定從伺服器登入的使用者名稱和密碼並授權。

   grant replication slave,replication client on *.* to [email protected]‘192.168.255.2‘ identified by ‘slave‘;

   flush privileges;

   \q


slave伺服器配置:

1- 在slave上使用master上建立的使用者名稱和密碼串連mysql資料庫,進行驗證。

   mysql -h 192.168.255.1 -u slave -p

2- 驗證成功後退出。

3- 編輯/etc/my.cnf檔案,設定伺服器server-id為2,id號建議使用伺服器ip地址最後一位。

4- 串連本地mysql資料庫,配置slave服務。

   reset master;


   change master to

   master_host=‘192.168.255.1‘,

   master_user=‘slave‘,

   master_password=‘slave‘,

   master_log_file=‘mysql-bin.000001‘,

   master_log_pos=0;


   slave start;

   show slave status\G

   \q


slave伺服器資訊:

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:transparent url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat scroll center;border:1px solid rgb(221,221,221);" alt="spacer.gif" />

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

兩個欄位資訊為Yes,表示主從配置成功。


測試:

在master伺服器上建立資料庫,然後在slave伺服器上查詢看是否存在剛建立的資料庫。


說明:

1- 安裝之前的安裝方法,預設開啟了bin日誌,所以master與slave服務的my.cnf設定檔修改server-id即可。

2- 因為伺服器是剛安裝配置完mysql,所以二進位檔案名稱與pos就可以寫成mysql-bin.000001和0。

3- 如果服務跑了一段時間再來類比這個情況,那先備份資料,然後清空資料庫目錄,然後使用mysql_install_db

   指令碼初始化資料庫。


本文出自 “whh881114” 部落格,請務必保留此出處http://whh881114.blog.51cto.com/9520067/1605245

02- MySQL主從複製(MySQL剛安裝完成)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.