docker pull mysql:latest
创建主数据库容器
docker run --name mysql-master -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
创建从数据库容器
docker run --name mysql-slave -p 3308:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
首先,进入容器:
docker exec -it mysql-master /bin/bash
root@c72a3032f986:/#
连接 MySQL
mysql -u root -p123456
修改 root 可以通过任何客户端连接
ALTER USER ‘root‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘123456‘;
修改 MySQL 配置文档 /etc/mysql/mysql.conf.d/mysqld.cnf
,在 [mysqld]
段添加以下配置:
log-bin=mysql-bin //[必须]启用二进制日志
server-id=1 //[必须]服务器标识ID,每台服务器唯一
首先,进入容器:
docker exec -it mysql-slave /bin/bash
root@89bdbb5786ab:/#
连接 MySQL
mysql -u root -p123456
修改 root 可以通过任何客户端连接
ALTER USER ‘root‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘123456‘;
修改 MySQL 配置文档 /etc/mysql/mysql.conf.d/mysqld.cnf
,在 [mysqld]
段添加以下配置:
log-bin=mysql-bin //[必须]启用二进制日志
server-id=2 //[必须]服务器标识ID,每台服务器唯一
首先连接 master 服务器,查看数据库状态:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
https://www.cnblogs.com/xuxiaobai13/p/12737197.html
https://www.cnblogs.com/python001-vip/p/12632492.html
https://blog.csdn.net/qq_37960603/article/details/82814939
原文:https://www.cnblogs.com/123qq/p/13408555.html