使用docker-conpose部署master库:
version: "3"
services:
mysql5.7:
image: mysql:5.7
ports:
- 3307:3306
volumes:
- ./data:/var/lib/mysql
- ./conf:/etc/mysql/conf.d
- ./logs:/logs
restart: always
privileged: true
environment:
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=root
改配置:
[mysqld]
lower_case_table_names=1
skip-name-resolve
max_allowed_packet = 100M
## 同一局域网内注意要唯一
server-id=100
## 开启二进制日志功能,名称可以随便取(关键)
log-bin=mysql-bin
重启 docker-compose restart mysql5.7
进入容器命令行docker-compose exec mysql5.7 bash
连接mysql
root@c2c81ec6363a:/# mysql -hlocalhost -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Master数据库创建数据同步用户,授予用户 syncREPLICATION SLAVE
权限和REPLICATION CLIENT
权限,用于在主从库之间同步数据。
mysql> CREATE USER 'sync'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'sync'@'%';
Query OK, 0 rows affected (0.00 sec)