docker安装mysql,并配置部分表同步
拉取数据库镜像
docker pull mysql:5.7
获取数据库Docker镜像
1. 设置虚拟网卡(用于固定dockerip)
详细参考:https://www.cnblogs.com/lsz920210/p/13583499.html
docker network create --subnet=172.19.0.0/16 bindIpNetwork
运行镜像
docker run -p 12345:3306 --name cjgk_cj -v /home/docker/cjgk_cj/conf:/etc/mysql/conf.d -v /home/docker/cjgk_cj/logs:/logs -v /home/docker/cjgk_cj/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=finance.Bjsasc.com110 --restart=always --net bindIpNetwork --ip 172.19.0.11 -d mysql:5.7
docker run -p 12346:3306 --name cjgk_ht -v /home/docker/cjgk_ht/conf:/etc/mysql/conf.d -v /home/docker/cjgk_ht/logs:/logs -v /home/docker/cjgk_ht/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=finance.Bjsasc.com110 --restart=always --net bindIpNetwork --ip 172.19.0.12 -d mysql:5.7
至此数据库创建和启动成功
数据库部分表自动同步设置
创建同步用户并授权
grant replication slave, replication client on *.* to 'syncuser'@'%' identified by 'Bjsasc123';
配置数据库
change master to master_host='172.19.0.11',master_user='syncuser',master_password='Bjsasc123',master_port=3306,MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS= 154;
change master to master_host='172.19.0.12',master_user='syncuser',master_password='Bjsasc123',master_port=3306,MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS= 154;