將Uhost上的MySQL遷移到UDB

來源:互聯網
上載者:User

標籤:mysql   innodb   

一 應用情境描述

最近我們部署在Ucloud的一台雲主機由於底層硬體故障,Ucloud建議將這台雲主機作動態遷移,但是由於這台伺服器上部署有MySQL資料庫,資料量太大,雲主機遷移會很慢。所以我們需要先將這台雲主機的MySQL遷移到UDB,然後切換程式裡面的MySQL配置。


二 具體操作步驟

1.將Uhost上的MySQL匯出一份

mysqldump  -A --ignore-table=mysql.slow_log  --master-data=1 --single-transaction --quick -R --event -uroot -p > mysql_data20150203.sql


如果資料量太大,匯出的時間會很長,可以使用screen開一個視窗,可以隨時查看進度


-A 匯出所有資料庫

--ignore-table=<database>.<table>   不匯出指定表,如果有多個表不需要匯出,需要使用多個--ignore-table 參數


--master-data=[1|2]  如果設定--master-data=1將會顯示如下資訊:

        

---- Position to start replication or point-in-time recovery from--CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000003‘, MASTER_LOG_POS=3018292;--

這樣如果設定SLAVE的時候就不需要再單獨指定MASTER_LOG_FILE和MASTER_LOG_POS

如何設定--master-data=2,CHANGE MASTER TO 這一行將被注釋掉,當設定SLAVE的同步需要按照這裡的提示設定MASTER_LOG_FILE和MASTER_LOG_POS


  設定--master-data參數,配合--single-transaction參數可以不鎖表。


--single-transaction 保證備份資料的一致性,目前支援InnoDB


--quick Don‘t buffer query, dump directly to stdout.

-R 匯出函數和預存程序

--event Dump events


2.匯入資料到UDB

如果資料量太大,匯入的時間會很長,可以使用screen開一個視窗,可以隨時查看進度


mysql -h10.4.21.160 -uroot -p

mysql> source mysql_data20150203.sql


這裡匯入資料的時候有幾個小故障,由於UDB預設設定為Master,開啟了binlog,所以匯入資料的時候UDB的binlog增長太快,把500G磁碟寫滿後,匯入失敗。


可以設定匯入的時候不寫入binlog


SET sql_log_bin=0


由於使用mysqldump匯出的時候使用了 -A 參數,沒有過濾掉mysql庫,所以如果Uhost的MySQL裡面沒有設定除了root帳號外具有合適許可權登入的帳號,那麼在以下設定Slave的時候就會出錯。

這種情況下,可以使用--skip-grant-tables參數重新啟動UDB,然後再重新設定root帳號密碼。


3.設定UDB為MySQL Slave,從Uhost上的MySQL同步資料

CHANGE MASTER TO MASTER_HOST=‘10.4.3.149‘,MASTER_PORT=3306,MASTER_USER=‘repl_user‘,MASTER_PASSWORD=‘xyzzy‘,MASTER_LOG_FILE=‘mysql-bin.000003‘, MASTER_LOG_POS=3018292;


同步過程中,查看Slave的狀態資訊,主要觀察以下幾個參數

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Seconds_Behind_Master: 0


在同步過程中,Seconds_Behind_Master 數值會越來越小,如果同步出錯,會有報錯資訊顯示


mysql> show slave status\G*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 10.4.3.149                  Master_User: repl_user                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: mysql-bin.000005          Read_Master_Log_Pos: 925459151               Relay_Log_File: mysql-relay.000012                Relay_Log_Pos: 294731160        Relay_Master_Log_File: mysql-bin.000005             Slave_IO_Running: Yes            Slave_SQL_Running: Yes              Replicate_Do_DB:           Replicate_Ignore_DB:            Replicate_Do_Table:        Replicate_Ignore_Table:       Replicate_Wild_Do_Table:   Replicate_Wild_Ignore_Table:                    Last_Errno: 0                   Last_Error:                  Skip_Counter: 0          Exec_Master_Log_Pos: 925459151              Relay_Log_Space: 294731312              Until_Condition: None               Until_Log_File:                 Until_Log_Pos: 0           Master_SSL_Allowed: No           Master_SSL_CA_File:            Master_SSL_CA_Path:               Master_SSL_Cert:             Master_SSL_Cipher:                Master_SSL_Key:         Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No                Last_IO_Errno: 0                Last_IO_Error:                Last_SQL_Errno: 0               Last_SQL_Error:   Replicate_Ignore_Server_Ids:              Master_Server_Id: 11 row in set (0.00 sec)mysql>



本文出自 “Linux SA John” 部落格,請務必保留此出處http://john88wang.blog.51cto.com/2165294/1612777

將Uhost上的MySQL遷移到UDB

聯繫我們

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