mysql replication 問題

來源:互聯網
上載者:User

標籤:mysql replication

今天又犯二了,居然把mysql的複製給忘了,也算醉了,再次總結mysql 主從:

公司的db01-fk(172.33.4.155)機器出了問題,需要換新的機器。這台機器上的mysql也是從中國db01複製的,所以解決思路:1、從中國db01備份資料庫,並將備份檔案傳至FK;2、在FK site 新db01-fk上還原資料庫,並設定master地址及相關參數,實現複製;

具體操作如下:

1、CN db01 備份資料庫,並傳至新db01-fk,操作如下:

[[email protected] ~]# mysqldump -A  --master-data=1 --single-transaction --events | gzip > /tmp/fulldb-16-12-05.sql.gz

[[email protected] ~]# ll -h /tmp/fulldb-16-12-05.sql.gz

-rw-r--r-- 1 root root 411M Dec  5 15:15 /tmp/fulldb-16-12-05.sql.gz

[[email protected] ~]# aws s3 cp /tmp/fulldb-16-12-05.sql.gz  s3://yeecalllogs-mb/

upload: ../tmp/fulldb-16-12-05.sql.gz to s3://yeecalllogs-mb/fulldb-16-12-05.sql.gz

[[email protected] ~]#


2、在db01-fk(new) 複製原db01-fk的設定檔、密鑰檔案,啟動服務,設定遠程master主機的相關參數

[[email protected] ~]# rsync -avzoptgl --progress  172.33.4.155:/home/mysql/  /home/mysql/

[[email protected] ~]# rsync -avzoptgl --progress  172.33.4.155:/etc/my.cnf  /etc/my.cnf

[[email protected] ~]# service mysqld start

[[email protected] ~]# mysql

mysql> change master to

    -> master_host=‘1.1.1.1‘,

    -> master_user=‘repl‘,

    -> master_password=‘123456789‘,

    -> master_port=13306,

    -> master_ssl=1,

    -> master_ssl_ca=‘/home/mysql/ssl/ca.crt‘,

    -> master_ssl_cert=‘/home/mysql/ssl/4.idc.ycall.com.crt‘,

    -> master_ssl_key=‘/home/mysql/ssl/4.idc.ycall.com.key‘;

Query OK, 0 rows affected (0.02 sec)

mysql> exit

在db01-fk(new)上還原資料庫,進行複製 

[[email protected] ~]# aws s3 cp s3://yeecalllogs-mb/fulldb-16-12-05.sql.gz /tmp/

download: s3://yeecalllogs-mb/fulldb-16-12-05.sql.gz to ../tmp/fulldb-16-12-05.sql.gz

[[email protected] ~]# gzip -d /tmp/fulldb-16-12-05.sql.gz

[[email protected] ~]# grep -P -io "change master to .*\d;$" /tmp/fulldb-16-12-05.sql

CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000069‘, MASTER_LOG_POS=8105870;

[[email protected] ~]# mysql < /tmp/fulldb-16-12-05.sql

[[email protected] ~]# mysql

mysql> start slave ;

mysql> show slave status \G 

[[email protected] ~]#


說明:

mysqldump --help

--master-data[=#]  This causes the binary log position and filename to be 

                      appended to the output. If equal to 1, will print it as a 

                      CHANGE MASTER command; if equal to 2, that command will 

                      be prefixed with a comment symbol. This option will turn 

                      --lock-all-tables on, unless --single-transaction is 

                      specified too (in which case a global read lock is only 

                      taken a short time at the beginning of the dump; don‘t 

                      forget to read about --single-transaction below). In all 

                      cases, any action on logs will happen at the exact moment 

                      of the dump. Option automatically turns --lock-tables 

                      off.

--master-data[=#]      在備份匯出的檔案裡追加二進位binlog檔案的位置和名稱 

                        如果值等於1,就會添加一個CHANGE MASTER語句 

                        如果值等於2,就會在CHANGE MASTER語句前添加註釋 

                        這個參數會--lock-all-tables鎖表,除非指定了--single-transaction 

                        這種情況下,鎖表只會在dump開始的時候持續一小段時間,照理說 

                        在dump的時候,任何動作都會影響到binlog檔案 

                        dump結束之後,選項會自動關閉鎖表功能

    分析:如果在恢複DB之前指定  change master to 的 host port .....,然後再恢複DB, 這樣 dump 檔案中帶的  master_log_file 和 master_log_pos 才會生效。因為一旦修改master host(即使修改前後的值相同),就會產生新的file和pos,原來dump檔案的語句就被衝掉了。所以這種方式必須首先指定host,然後恢複,最後 start slave; 

    當然:我上次操作,在mysqldump時沒加這兩參數,使用了-x 鎖表功能 ,但在mysqldump過程中,在主庫上 show master status  , 查看了 position 及 logfile,然後記下這兩項值,以便在從庫change master to 操作時指定這些參數。

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

mysql replication 問題

聯繫我們

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