一、修改主庫my.cnf文件
vi /etc/my.cnf
#在[mysqld]下添加如下配置
log_bin=master-bin
log_bin_index=master-bin.index
innodb_file_per_table=ON
binlog_format=MIXED
server_id=1
sync_binlog=1
二、添加一個從服務器創建複製數據的用戶
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'從庫的ip' IDENTIFIED BY '密碼自己寫';
FLUSH PRIVILEGES;
三、查看主庫信息
show master status;
會得到兩個值,下面有用
四、修改從庫my.cnf文件
vi /etc/my.cnf
innodb_file_per_table=ON
relay_log = relay-log
relay_log_index = relay-log.index
server_id=2
read_only=ON
五、添加登陸複製相關信息,並啓動同步
change master to master_host='主庫ip',master_port=3306,master_user='slave',master_password='剛纔設置的密碼',master_log_file='第三步的file值',master_log_pos=第三步position的值;
start slave;
六、測試
#在從庫查詢狀態
show slave status;
這兩值爲yes即爲成功
可在主庫創建test庫,觀察是否從庫也同時創建