(1) 、準備兩臺主機,主服務器my.cnf配置log-bin=master-bin.log ,server-id=1 ,從服務器server-id=1,級聯要多加log-slave-updates=1。
(2) ,在主庫上,授權一個複製使用的帳號,只授予super,replication slave權限
mysql> grant super,replication slave on *.* to 'test'@'192.168.169.162' identified by '123456';
mysql> flush privileges;
(3) 、將主庫上當前二進制日誌名和pos值打印出來
mysql> show master status;
(4),在從數據庫上配置連接主數據庫配置,指定複製使用的賬號/密碼,主服務器的ip、端口、以及日誌文件及pos位置等
mysql> change master to --配置從服務器連接主
-> master_user='qy', --主服務器建立複製的帳號
-> master_password='111', --密碼
-> master_host='192.168.169.161', --主服務器IP
-> master_port=3307, --端口,注:不能加引號
-> master_log_file=' master-bin.000001', --主上面查到的文件名
-> master_log_pos=338; --主上面查到的位置號
(5)、配置好後,從數據庫上啓動slave進程,讓從數據庫的I/O和SQL線程生效
mysql> start slave;
(6)、這時在從服務器上執行: show slave status\G;