標籤:mysql master slave 主從複製
1、Master伺服器配置。
[[email protected] ~]# vim /etc/my.cnf log-bin=master-binlog-bin-index=master-bin.indexinnodb_file_per_table = 1binlog_format=mixedserver-id = 1 #必須是唯一值sync_binlog=1 #設定主從同步二進位記錄檔mysql> GRANT REPLICATION SLAVE ON *.* TO ‘repluser‘@‘172.16.%.%‘ IDENTIFIED BY ‘replpass‘;mysql> flush privileges;mysql> SHOW MASTER STATUS\G;
2、Slave伺服器配置。
[[email protected] ~]# vim /etc/my.cnf relay-log = relay-logserver-id = 2relay-log-index = relay-log.indexread-only = on #資料庫唯讀鎖定,不影響主從複製skip_slave_start=1 #禁止slave隨資料庫啟動mysql> CHANGE MASTER TO MASTER_HOST=‘172.16.23.22‘,MASTER_LOG_FILE=‘master-bin.000001‘,MASTER_USER=‘repluser‘,MASTER_PASSWORD=‘replpass‘,MASTER_LOG_POS=4;mysql> HELP CHANGE MASTER TO #查看命令用法mysql> SHOW SLAVE STATUS\G; #查看狀態mysql> START SLAVE; #啟動slave服務mysql> START SLAVE IO_THREAD; #依次啟動slave服務mysql> START SLAVE SQL_THREAD; mysql> show global variables like ‘read%‘; #查看全域變數驗證唯讀鎖定mysql> set global read_only=off; #臨時修改系統變數[[email protected] ~]# cat /datadir/master.info #檔案記錄了master的串連帳號資訊[[email protected] ~]# cat /datadir/relay-log.info #檔案記錄了中繼日誌的資訊