centos 主從複製

來源:互聯網
上載者:User

標籤:


1.主伺服器rpm安裝mysql

2.複製一台伺服器叫slave(從伺服器),一會兒要用

3.在主伺服器,修改my.cnf檔案 找到server-id,在它的下面
加上 binlog-do-db = houdunwang

4.在主伺服器,進入到mysql,建立houdunwang資料庫,
隨便建一張表,隨便插入一些資料

5.開啟從伺服器,設定ip,保證能上網

6.開啟主伺服器,進入到mysql,添加mysql帳號
grant replication slave on *.* to ‘slave‘@‘192.168.1.250‘ identified by ‘admin888‘;

重新整理授權表,讓帳號立刻生效
flush privileges;

//查看使用者是否已經添加
select user,host from mysql.user;

//鎖定主伺服器的所有的表
flush tables with read lock;

//先退出mysql,然後匯出sql
mysqldump -uroot -p houdunwang>houdunwang.sql

//從主伺服器把sql檔案複製到從伺服器的家目錄
scp houdunwang.sql [email protected]:~


7.開啟從伺服器,編輯/etc/my.cnf,把server-id改成2
重啟mysql,進入到mysql,
建立houdunwang庫,
退出mysql,執行匯入操作
mysql -uroot -p houdunwang<houdunwang.sql


8.在主伺服器裡面的mysql,打以下命令,查看bin-log狀態
show master status;

9.在從伺服器的mysql
change master to master_host=‘192.168.21.109‘,master_user=‘slave‘,master_password=‘admin888‘,master_log_file=‘mysql-bin.000005‘,master_log_pos=725;

10.在從伺服器mysql開啟同步
start slave

11.把主伺服器的表解鎖,在主伺服器的mysql裡面操作
unlock tables;
















centos 主從複製

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.