基于镜像安装mysql

时间:2021-12-08 23:47:38
====================master====================
docker run -p 3306:3306 --name mysql-master \
-v /mydata/mysql/master/log:/var/log/mysql \
-v /mydata/mysql/master/data:/var/lib/mysql \
-v /mydata/mysql/master/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7 vim /mydata/mysql/master/conf/my.cnf [client]
default-character-set = utf8 [mysql]
default-character-set = utf8 [mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve server-id = 1 #开启binlog
log_bin = mysql-bin
read-only = 0 #同步的数据库
binlog-do-db = gmall_ums
binlog-do-db = gmall_pms
binlog-do-db = gmall_oms
binlog-do-db = gmall_sms
binlog-do-db = gmall_cms #忽略同步的数据库
replicate-ignore-db = mysql
replicate-ignore-db = sys
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema docker restart mysql-master docker exec -it mysql-master /bin/bash mysql -u root -p # 授权root用户
grant all privileges on *.* to root@'%' identified by '' with grant option;
flush privileges;
# 在Master上增加一个账号专门用于同步
GRANT REPLICATION SLAVE ON *.* TO 'backup'@'%' IDENTIFIED BY ''; docker restart mysql-master ====================slaver====================
docker run -p 3316:3306 --name mysql-slaver-01 \
-v /mydata/mysql/slaver/log:/var/log/mysql \
-v /mydata/mysql/slaver/data:/var/lib/mysql \
-v /mydata/mysql/slaver/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7 vim /mydata/mysql/slaver/conf/my.cnf [client]
default-character-set = utf8 [mysql]
default-character-set = utf8 [mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve server-id = 2 #开启binlog
log_bin = mysql-bin
read-only = 1 #同步的数据库
binlog-do-db = gmall_ums
binlog-do-db = gmall_pms
binlog-do-db = gmall_oms
binlog-do-db = gmall_sms
binlog-do-db = gmall_cms #忽略同步的数据库
replicate-ignore-db = mysql
replicate-ignore-db = sys
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema docker restart mysql-slaver-01 docker exec -it mysql-slaver-01 /bin/bash mysql -u root -p # 授权root用户
grant all privileges on *.* to root@'%' identified by '' with grant option;
flush privileges; # 告诉slaver同步账户 https://blog.csdn.net/jesseyoung/article/details/41942809
CHANGE MASTER TO MASTER_HOST = '192.168.20.130', MASTER_USER = 'backup', MASTER_PASSWORD = '', MASTER_PORT = 3306, MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 0; docker restart mysql-slaver-01 docker exec -it mysql-slaver-01 /bin/bash mysql -u root -p # 开始同步
start slave; # 查看同步状态
show slave status\G;