mysql主從複製

來源:互聯網
上載者:User

標籤:

參考文檔:

http://www.linuxidc.com/Linux/2013-10/90800.htmhttp://369369.blog.51cto.com/319630/790921/

 

大致步驟:

MySQL主從複製master:192.168.1.1slave: 192.168.1.21.主從伺服器分別操作如下:1.1版本一致1.2初始化表,並在後台啟動mysql1.3修改root密碼2.修改主伺服器mastervi /etc/my.cnf:    [mysqld]    server-id=1                            //[必須]伺服器唯一ID,預設為1,一般去IP最後一段    log-bin=$MYSQL_HOME/data/mysql-bin    //[必須]啟動二進位日誌    binlog_format=mixed                    //指定二進位日誌的記錄格式為混合模式 3.修改從伺服器slavevi /etc/my.cnf:    [mysqld]    server-id=2        //[必須]伺服器唯一ID,預設為1,一般去IP最後一段    relay-log=$MYSQL_HOME/data/mysql-relay-bin //啟動中繼日誌    read-only=yes    //開啟唯讀模式4.重啟兩台伺服器的mysql/etc/init.d/mysql restart5.在主伺服器建立賬戶並收取/usr/local/mysql/bin/mysql -uroot -pmypassmysql>GRANT REPLICATION SLAVE ON *.* to ‘mysync‘@‘%‘ identified by ‘q123456‘; //一般不用root帳號,“%”表示所有用戶端都可能連,只要帳號,密碼正確,此處可用具體用戶端IP代替,如192.168.145.226,加強安全。mysql>FLUSH PRIVILIGES;6.登陸主伺服器mysql,查詢master狀態mysql>flush tables with read lock;    //先鎖定下表,防止資料寫入造成master狀態發生變化mysql>show master status;   +------------------+----------+--------------+------------------+   | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |   +------------------+----------+--------------+------------------+   | mysql-bin.000004 |      308 |              |                  |   +------------------+----------+--------------+------------------+   1 row in set (0.00 sec)   註:執行完此步驟後不要再操作主伺服器MYSQL,防止主伺服器狀態值變化mysql>unlock tables;     //配置完slave後,將表解鎖即可   7.配置從伺服器slavemysql>change master to master_host=‘192.168.1.1‘,master_user=‘mysync‘,master_password=‘q123456‘,master_log_file=‘mysql-bin.000004‘,master_log_pos=308;   //注意不要斷開,“308”無單引號。mysql>start slave;    //啟動從伺服器複製功能8.檢查從伺服器複製狀態mysql> show slave status\G    *************************** 1. row ***************************    Slave_IO_State: Waiting for master to send event    Master_Host: 192.168.1.1  //主伺服器地址    Master_User: myrync         //授權帳戶名稱,盡量避免使用root    Master_Port: 3306           //資料庫連接埠,部分版本沒有此行    Connect_Retry: 60    Master_Log_File: mysql-bin.000004    Read_Master_Log_Pos: 600        //#同步讀取二進位日誌的位置,大於等於>=Exec_Master_Log_Pos    Relay_Log_File: ddte-relay-bin.000003    Relay_Log_Pos: 251    Relay_Master_Log_File: mysql-bin.000004    Slave_IO_Running: Yes       //此狀態必須YES    Slave_SQL_Running: Yes       //此狀態必須YES    ......註:Slave_IO及Slave_SQL進程必須正常運行,即YES狀態,否則都是錯誤的狀態(如:其中一個NO均屬錯誤)。以上操作過程,主從伺服器配置完成。

 

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.