step by step配置mysql復制 采用全庫復制的方案,方便管理mysql 5.5 + rhel5.8 10.4.11.12 master 10.4.11.13 slave ---Master端設置 1, 創建復制帳號,需要復制和slave權限 mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO repl@'10.4.11.12 IDENTIFIED BY 'mysql; Query OK, 0 rows affected (0.00 sec) 2, 修改參數,並重啟生效 每個服務器必須有唯一的server-id,默認為1,為了防止沖突,一般建議設置為IP地址的後幾位,本例設置為12,通過修改主庫的my.cnf文件實現 #skip-networking server-id = 12 # Uncomment the following if you want to log updates log-bin=mysql-bin 重啟mysql service mysql restart ---slave端的設置 3,slave庫的參數設置,同樣需要重啟生效 vi /etc/my.cnf #skip-networking server-id = 13 # Uncomment the following if you want to log updates log-bin=mysql-relay-bin 4,master導出數據到slave庫 如果數據庫使用的是MyISAM表類型的話,可按如下方式操作: shell> mysqldump --all-databases --master-data=1 > data.sql 如果數據庫使用的是InnoDB表類型的話,則應該使用single-transcation: shell> mysqldump --all-databases --single-transaction --master-data=1 > data.sql slave端導入數據 mysql < data.sql 5,查看master的配置 mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) 6,啟動復制,slave端運行如下命令 --配置復制的指向 CHANGE MASTER TO MASTER_HOST='10.4.11.12', MASTER_USER='repl', MASTER_PASSWORD='mysql', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=0; --開始復制 mysql> start slave ; Query OK, 0 rows affected (0.00 sec) 7,查看復制的狀態,注意slave_io_state, slave_io_Running,和slave_sql_running三列的值 mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.16.251.11 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 1278 Relay_Log_File: linux2-relay-bin.000002 Relay_Log_Pos: 503 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: …….. 8,測試復制情況 Master端新建一個表 Slave查看是否復制完成