docker搭建MySQL主從環境
阿新 • • 發佈:2019-01-08
從docker hub上下載最新的MySQL映象,遵循如下步驟,即可利用docker構建MySQL主從環境。
1.執行主庫容器
docker run --name mysql -p 33061:3306 -e MYSQL_ROOT_PASSWORD=root -v /Users/derrick.yang/mysql/data/:/var/lib/mysql/ -v /Users/derrick.yang/mysql/etc/:/etc/mysql/ 5fac85ee2c68
2.執行從庫容器
docker run --name mysql -p 33062:3306 -e MYSQL_ROOT_PASSWORD=root -v /Users/derrick.yang/mysql/data/:/var/lib/mysql/ -v /Users/derrick.yang/mysql/etc/:/etc/mysql/ 5fac85ee2c68
3.修改配置檔案
主庫配置檔案
server-id=1
log-bin=master-bin
log-bin-index=master-bin.index
重啟主庫,檢視主庫狀態
show master status;
從庫配置檔案
server-id=10 #唯一值,不要與主庫相同
log-bin=master-bin
log-bin-index=master-bin.index
重新啟動從庫,配置從庫訪問主庫的資訊:
change master to master_host='104.224.163.143' ,master_user='root',master_password='root',master_log_file='master-bin.000006',master_log_pos=107;
啟動slave,檢視狀態
start slave;
show slave status\G;