參考
http://www.cnblogs.com/future2012lg/p/4873805.html
主配置
修改my.ini文件,在[mysqld]下增加以下配置:
#主服務器二進制日誌文件前綴名
log-bin=master-bin
#索引文件
log-bin-index=master-bin.index
#開啓innodb的一表一個文件的設置
innodb_file_per_table=1
#必須是唯一的
server-id=1
#忽略複製的db
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
binlog_format=mixed
#在主服務器上進行設置,用於事務安全
sync-binlog=1
增加同步數據賬戶
grant replication slave on *.* to 'repl'@'%' identified by '123456';
flush privileges;
重啓主mysql服務
連上主mysql後輸入
show master status;
記錄file,position字段,後面從開啓複製用
從配置
修改my.ini文件,在[mysqld]下增加以下配置:
#設置中繼日誌
relay-log=relay-log
#中繼日誌索引
relay-log-index=relay-log.index
#id不要和主服務器的一樣
server-id=2
#設置非管理員組只讀
read-only=ON
重啓從mysql服務
連上從mysql後輸入
change master to master_host='127.0.0.1',master_port=3307,master_user='repl',master_password='123456',master_log_file='master-bin.000001',master_log_pos=154;
輸入show slave status\G可以查看狀態
start slave;
主主配置
即互爲主從即可
前面的配置爲前兩個mysql,此爲第三個mysql
#主服務器二進制日誌文件前綴名
log-bin=master-bin
#索引文件
log-bin-index=master-bin.index
#開啓innodb的一表一個文件的設置
innodb_file_per_table=1
#必須是唯一的
server-id=3
#忽略複製的db
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
binlog_format=mixed
#在主服務器上進行設置,用於事務安全
sync-binlog=1
#設置中繼日誌
relay-log=relay-log
#中繼日誌索引
relay-log-index=relay-log.index
auto-increment-increment=2
auto-increment-offset=2
增加同步數據賬戶
grant replication slave on *.* to 'repl'@'%' identified by '123456';
flush privileges;
重啓主mysql服務
連上主mysql後輸入
show master status;
記錄file,position字段,後面從開啓複製用
change master to master_host='127.0.0.1',master_port=3307,master_user='repl',master_password='123456',master_log_file='master-bin.000001',master_log_pos=154;
輸入show slave status\G可以查看狀態
start slave;
第一臺主mysql配置
#主服務器二進制日誌文件前綴名
log-bin=master-bin
#索引文件
log-bin-index=master-bin.index
#開啓innodb的一表一個文件的設置
innodb_file_per_table=1
#必須是唯一的
server-id=1
#忽略複製的db
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
binlog_format=mixed
#在主服務器上進行設置,用於事務安全
sync-binlog=1
#設置中繼日誌
relay-log=relay-log
#中繼日誌索引
relay-log-index=relay-log.index
auto-increment-increment=2
auto-increment-offset=1
重啓主mysql服務
連上主mysql後輸入
show master status;
記錄file,position字段,後面從開啓複製用
change master to master_host='127.0.0.1',master_port=3309,master_user='repl',master_password='123456',master_log_file='master-bin.000001',master_log_pos=154;
輸入show slave status\G可以查看狀態
start slave;