17.1 MySQL主從介紹17.2 準備工作17.3 配置主17.4 配置從17.5 測試主從同步

來源:互聯網
上載者:User

標籤:十五周一次課(4月2日)

17.1 MySQL主從介紹
18.
主要應用的情境
1.資料備份
2.做為讀的庫使用,減輕主庫的壓力
17.2 準備工作
將主從都啟動mysql服務,linux-01作為主mysql,linux-02作為從mysql
17.3 配置主
在主上操作
修改my.cnf,增加server-id=130和log_bin=aminglinux1

修改完設定檔後,啟動或者重啟mysqld服務
/etc/inir.d/mysqld restart
查看mysql目錄下會產生aminglinux1.index索引檔案與aminglinux1.000001記錄檔,還會產生更多的記錄檔,這個檔案是主從的根本,非常重要,沒有這個檔案主從是沒有辦法完成。

把mysql庫備份並恢複成aming庫,作為測試資料,以下是操作
mysql -uroot進入資料庫
mysqldump -uroot mysql > /tmp/mysql.sql,備份資料庫
mysql -uroot -e “create database aming” 建立資料庫
mysql -uroot aming < /tmp/mysql.sql 恢複資料庫
建立用作同步資料的使用者
grant replication slave on . to ‘repl‘@192.168.137.129 identified by ‘password‘; 指定用記許可權與IP
flush tables with read lock; 鎖一下表,是為了不讓它再寫入資料,狀態先保持在這裡
show master status;

將主同步的資料庫都備份後再拷貝到從機器去

17.4 配置從

查看my.cnf,配置server-id=132,要求和主不一樣
vi /etc/my.cnf

修改完設定檔後,啟動或者重啟mysqld服務
/etc/init.d/mysqld restart
把主上aming庫同步到從上
scp 192.168.137.128:/tmp/*.sql /tmp/ 將主的庫拷貝到從的/tmp/

進入從資料庫
mysql -uroot
建立庫aming,zrlog .blog

恢複資料

mysql -uroot
stop slave;
change master to master_host=‘‘, master_user=‘repl‘, master_password=‘‘, master_log_file=‘‘, master_log_pos=xx

判定主從到底有沒有成功

還要到主上執行 unlock tables恢複寫操作
17.5 測試主從同步

以後指定某一個庫或忽略某一個庫,用這2個參數就可以了
replicate_wild_do_table= //如aming.%, 支援萬用字元%
replicate_wild_ignore_table=

17.1 MySQL主從介紹17.2 準備工作17.3 配置主17.4 配置從17.5 測試主從同步

聯繫我們

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