1、前提条件
- 已打开防火墙 3306 3307 3308 端口
- 已获取 my.cnf 配置文件
2、配置文件
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
skip-host-cache
skip-name-resolve
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#log-error = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
log-bin=mysql-bin
server-id=1
# 修改最后的值即可
3、命令
docker run --name 集装箱名 -p 端口:映射端口 -e MYSQL_ROOT_PASSWORD=密码-d MySQL版本
docker cp 配置好的文件位置 集装箱名:对应位置
# 默认为 /etc/my.cnf
docker restart 各集装箱名(空格隔开)
4、操作Navicat
- 所需命令
stop slave;
# 停止从机
CHANGE MASTER TO MASTER_HOST='对应IP', MASTER_PORT=端口, MASTER_USER='用户', MASTER_PASSWORD='密码',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=154;
# 连接
# 后两点需要查看 master 信息
START SLAVE;
# 启动从机
show slave status;
# 查看从机状态
show master status;
# 查看主机状态
- 主机信息
- 查看从机连接状态
5、操作主机后刷新从机查看
PS
本大可不必发表本文,but 博主的配置被自个瞎搞坏了,左摸右摸没办法了抱着死马当活马医的心态,结果一下可以了
附上裂开瞬间