使用 Windows powershell
cmd下使用会出现一系列问题
拉取镜像
docker pull mysql
创建容器
docker create --name mysqlsrv1 -v E:\docker\db\mysql\my1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=你的密码 -p 3307:3306 mysql
启动容器
docker start mysqlsrv1
测试
docker ps
docker exec -it mysqlsrv01
mysql -uroot -p
tip:若提示 Error response from daemon: Drive has not been shared
请将设备磁盘设置为共享
tip:若此时使用 navicat 连接可能会出现
alter user 'root'@'%' identified by '你的密码' password expire never;
alter user 'root'@'%' identified with mysql_native_password by '你的密码';
flush privileges;
alter user 'root'@'%' identified by '你的密码';
主从配置
# 高版本 当前版本:mysql Ver 14.14 Distrib 5.6.41, for Linux (x86_64) using EditLine wrapper
create user 'repldocker'@'192.168.0.%' identified by '密码';
GRANT REPLICATION SLAVE ON *.* TO 'repldocker'@'192.168.0.%';
GRANT REPLICATION SLAVE ON *.* TO 'repldocker'@'192.168.0.%'; IDENTIFIED BY '密码';
GRANT REPLICATION SLAVE ON *.* TO 'repldocker'@'192.168.0.%' IDENTIFIED BY '密码' with grant option;
修改主服务器配置
[mysqld]
log-bin=mysql-bin //[必须]启用二进制日志
server-id=140 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
重启 service mysql restart
查看 binlog是否启用 show variables like '%log_bin%' ;
+---------------------------------+--------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/mysql-bin |
| log_bin_index | /var/lib/mysql/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+--------------------------------+
docker 安装 vim
-
apt update
同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引 -
apt install vim
安装 vim
尝试源码安装
ftp://ftp.vim.org/pub/vim/unix/
https://blog.csdn.net/gatieme/article/details/43883261
docker 下配置 mysql 从服务器 binlog
vim /etc/mysql/my.cnf
添加
log-bin=mysql-bin
server-id=3307
重启mysql容器
docker restart mysqlsrv1
简化版
docker exec mysqlsrv1 bash -c "echo 'log-bin=mysql-bin' >> /etc/mysql/my.cnf"
docker exec mysqlsrv1 bash -c "echo 'server-id=3307' >> /etc/mysql/my.cnf"
docker restart mysqlsrv1
change master to master_host='192.168.0.47', master_port=3306,master_user='repldocker',master_password='master中创建的用户密码',master_log_file='mysql-bin.000001',master_log_pos=120;
tip:配置中间用 ,
尽量不用 空格
成功连接状态
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event 之前配置错误时一直显示: Connecting to master
Master_Host: 192.168.0.47
Master_User: repldocker
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 892
Relay_Log_File: fe1d594c7842-relay-bin.000002
Relay_Log_Pos: 318
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes 之前配置错误时一直显示: Connecting
Slave_SQL_Running: Yes
Master_Server_Id: 47
Master_UUID: 0684ced9-af5b-11e8-94fd-00163e0hhhhh 之前配置错误时此处为空;
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400