Ubuntu 14.04 MySQL同步

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   資料   sp   div   

主伺服器:192.168.2.212

從伺服器:192.168.2.211 主伺服器(192.168.2.212):先到/etc/mysql/my.cnf下 將
bind-address 127.0.0.1

注釋掉

#bind-address 127.0.0.1

允許非本機訪問。

登陸mysql

mysql -uroot -p
grant replication slave,reload,super on *.* to slave@192.168.2.211 identified by ‘123456‘

可以在從伺服器(192.168.2.211)遠程測試一下

mysql -uslave -h192.168.2.212 -p

修改主伺服器my.cnf

sudo nano /etc/mysql/my.cnf

以下內容必須在[mysqld]模組中

server-id=1log_bin=/var/log/mysql/mysql-bin.logbinlog_do_db=ccsbinlog_ignore_db=mysql

do_db和ignore_db分別是同步的資料庫和不同步的資料庫,有多條就寫多行。

重啟mysql

sudo /etc/init.d/mysql restart

進mysql

mysql -uroot -p
show variables like ‘log%‘;

log_bin應該為ON

show master status;

則能看到對應得file position 資訊,這些在從機設定的時候要用到。

 

從伺服器(192.168.2.211):

配置my.cnf

server-id=2log_bin=/var/log/mysql/mysql-bin.logreplicate_do_db=ccs

重啟mysql

sudo /etc/init.d/mysql restart

進mysql:

mysql -uroot -p
stop slave;

 然後設定從master複製日誌配置

CHANGE MASTER TOMASTER_HOST=‘192.168.2.212‘,MASTER_USER=‘slave‘,MASTER_PASSWORD=‘123456‘,MASTER_PORT=3306,MASTER_LOG_FILE=‘mysql-bin.000006‘,MASTER_LOG_POS=277,MASTER_CONNECT_RETRY=10;

LOG_FILE和LOG_POS則是在master下show master status時候看到的file position資訊。

CONNECT_RETRY是每次重連的時間間隔

start slave;show slave status\G

在出現的資訊中找到 Slave_IO_Running/Slave_SQL_Running ,都為YES則成功了。

Ubuntu 14.04 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.