Mysql---主從複製

來源:互聯網
上載者:User

標籤:mysql 主從複製

mysql複製1.搭建一個master對應1個slave(只複製某個資料庫)(1)規劃網路和主從伺服器master:10.10.54.86slave:10.10.54.85(2)主機設定log-bin=master-binbinlog_format=mixedserver-id=1[[email protected] tmp]# /etc/init.d/mysqld restart ERROR! MySQL server PID file could not be found!Starting MySQL.. SUCCESS! (3)從機設定log-bin=slave-binbinlog_format=mixedserver-id=10[[email protected] ~]# /etc/init.d/mysqld restart ERROR! MySQL server PID file could not be found!Starting MySQL.. SUCCESS! (4)在master上面建立一個複製使用者並授予許可權mysql> grant replication slave on *.* to ‘emp‘@‘10.10.54.85‘ identified by ‘123‘;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)(5)查看master上的二進位日誌和position位置mysql> show master status;+-------------------+----------+--------------+------------------+| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |+-------------------+----------+--------------+------------------+| master-bin.000006 |      330 |              |                  |+-------------------+----------+--------------+------------------+1 row in set (0.00 sec)(6)備份master上的資料,把備份master資料庫還原到從庫上[[email protected] tmp]# mysqldump -uroot -p123456 --master-data=2 --single-transaction --flush-logs --database employees>employees.sql[[email protected] tmp]# mysql -uroot -p123456 -h10.10.54.85<employees.sql備忘:-p 後接的密碼為從機授權的密碼(7)在slave上面change master操作mysql> change master to master_host=‘10.10.54.86‘,master_user=‘emp‘, master_password=‘123‘,  master_log_file=‘master-bin.000006‘,master_log_pos=330;Query OK, 0 rows affected (0.01 sec)(8)在slave上啟動slavemysql> start slave;Query OK, 0 rows affected (0.00 sec)(9)查看slave的狀態mysql> show slave status\G;*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 10.10.54.86                  Master_User: emp                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: master-bin.000007          Read_Master_Log_Pos: 107               Relay_Log_File: nan85-relay-bin.000004                Relay_Log_Pos: 254        Relay_Master_Log_File: master-bin.000007             Slave_IO_Running: Yes            Slave_SQL_Running: Yes(10)測試主上:mysql> create database b;Query OK, 1 row affected (0.02 sec)從上:顯示有資料庫bmysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || a                  || b                  || employees          || mysql              || performance_schema || test               |+--------------------+測試在master上建立刪除添加資料,在slave上都能同步。


本文出自 “筆記” 部落格,請務必保留此出處http://sunflower2.blog.51cto.com/8837503/1651704

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.