主配置
[mysqld]
server_id = 1
log-bin= mysql-bin
read-only=0
binlog-do-db=meizhi
replicate-ignore-db=mysql
replicate-ignore-db=sys
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
从配置
[mysqld]
server_id = 3
log-bin= mysql-bin
read-only=1
binlog-do-db=meizhi
replicate-ignore-db=mysql
replicate-ignore-db=sys
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
Docker命令(记得修改自己的用户、密码 数据保存路径……)
sudo docker run -d -p 3307:3306 --name mysql2 -P -e mysqld -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_USER=guo -e MYSQL_PASSWORD=123456 -e MYSQL_DATABASE=meizhi -v /Users/gx/guo/mysql_data2:/var/lib/mysql -v /Users/gx/Documents/AutoSave/MYSQL/slaver.cnf:/etc/mysql/my.cnf mysql
sudo docker run -d -p 3308:3306 --name mysql3 -P -e mysqld -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_USER=guo -e MYSQL_PASSWORD=123456 -e MYSQL_DATABASE=meizhi -v /Users/gx/guo/mysql_data3:/var/lib/mysql -v /Users/gx/Documents/AutoSave/MYSQL/slaver2.cnf:/etc/mysql/my.cnf mysql
sudo docker run -d -p 3306:3306 --name mysql -P -e mysqld -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_USER=guo -e MYSQL_PASSWORD=123456 -e MYSQL_DATABASE=meizhi -v /Users/gx/guo/mysql_data:/var/lib/mysql -v /Users/gx/Documents/AutoSave/MYSQL/master.cnf:/etc/mysql/my.cnf mysql
关联命令
主库
GRANT REPLICATION SLAVE ON . to 'guo'@'%' identified by '123456';
show master status;
从库
change master to master_host='192.168.4.250',master_user='guo',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=0,master_port=3306;
start slave;
stop SLAVE;
show slave status;