Docker搭建mysql主从复制集群
搭建步骤
docker search mysql
docker pull mysql
mkdir -m777 /Users/a1/develop/docker/mysql/master01/data
mkdir -m777 /Users/a1/develop/docker/mysql/master01/conf
mkdir -m777 /Users/a1/develop/docker/mysql/slave01/data
mkdir -m777 /Users/a1/develop/docker/mysql/slave01/conf
vi my.cnf
[mysqld]
log-bin=mysql-bin
server-id=1
docker create --name mysql_master01 -p 3306:3306 \
-v /Users/a1/develop/docker/mysql/master01/data:/var/lib/mysql \
-v /Users/a1/develop/docker/mysql/master01/conf:/etc/my.cnf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql
docker start mysql_master01 && docker logs -f mysql_master01
docker exec -it mysql_master01 /bin/bash
mysql -uroot -p123456
create user 'trans'@'%' identified by 'trans' ;
grant replication slave on *.* to 'trans'@'%';
flush privileges ;
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000002 | 858 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
vi my.cnf
[mysqld]
server-id=2
docker create --name mysql_slave01 -p 3307:3306 \
-v /Users/a1/develop/docker/mysql/slave01/data:/var/lib/mysql \
-v /Users/a1/develop/docker/mysql/slave01/conf:/etc/my.cnf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql
docker start mysql_slave01 && docker logs -f mysql_slave01
(base) a1@192 conf % docker exec -it mysql_slave01 /bin/bash
bash-4.4
change master to
master_host='127.0.0.1',
master_user='trans',
master_password='trans',
master_port=3306,
master_log_file='binlog.000002',
master_log_pos=858;
start slave ;
show slave status ;