MySQL配置主從備份

來源:互聯網
上載者:User

標籤:mysql

首先,說一下叢集結構:

Master:10.1.111.46

Slave :10.1.111.47

 

一、對Master操作:

1、以root使用者登入Master,建立Slave複製的使用者:

mysql> GRANTREPLICATION SLAVE ON *.* TO ‘backup‘@‘10.1.111.47‘ IDENTIFIED BY ‘123456‘;

2、建立二進位記錄檔並修改記錄檔的使用者組

# mkdir -p/var/log/mysql# touch /var/log/mysql/mysql-bin.log# chown -R mysql.mysql /var/log/mysql

3、修改mysql設定檔 /etc/my.cfg

server-id           =1    #主機標示,整數log_bin             =/var/log/mysql/mysql-bin.log   #確保此檔案可寫read-only           =0  #主機,讀寫都可以binlog-do-db        =test1   #需要備份資料,多個寫多行binlog-ignore-db    =mysql #不需要備份的資料庫,多個寫多行

4、重啟mysql

# service mysqld restart

二、對Slave操作:

1、建立二進位記錄檔並修改記錄檔的使用者組

# mkdir -p/var/log/mysql# touch /var/log/mysql/mysql-bin.log# chown -R mysql.mysql /var/log/mysql

2、修改mysql設定檔 /etc/my.cfg

server-id           =2log_bin             =/var/log/mysql/mysql-bin.logmaster-host         =10.1.111.46master-user         =backupmaster-pass         =123456master-port         =3306master-connect-retry=60#如果從伺服器發現主伺服器斷掉,重新串連的時間差(秒)replicate-do-db     =test1 #只複製某個庫replicate-ignore-db =mysql #不複製某個庫

3、重啟mysql

# service mysqld restart

4、登陸mysql查看狀態

mysql> show slavestatus\G;mysql>                   ...       Relay_Master_Log_File: mysql-bin.000001            Slave_IO_Running:Yes           Slave_SQL_Running:Yes             Replicate_Do_DB: test1         Replicate_Ignore_DB: 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.