mysql主从复制(在虚拟机centos的docker下)

1.安装docker

Docker安装(CentOS)+简单使用-CSDN博客

2.部署2个mysql

docker run --name some-mysql1 -p 33061:3306  -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
docker run --name some-mysql2 -p 33062:3306  -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

3.试试连接的情况

window下 连接到虚拟机中的数据库

4.修改主从数据库的配置

主:

# Copyright (c) 2015, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# 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, version 2.0, 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  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html[mysqld]
log-bin = /var/lib/mysql/binlog
# 同一局域网中需要唯一
server-id = 1
# 需要同步的数据库
binlog-do-db = xl_game3pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
#log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

以下几个需要修改的(保存文件为 mysqld.cnf)

bin = /var/lib/mysql/binlog
server-id = 1
binlog-do-db = xl_game3

写好后 执行复制到docker的命令:

docker cp ./mysqld.cnf some-mysql1:etc/mysql/mysql.conf.d/

从:

# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# 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, version 2.0, 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  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
#log-error	= /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address	= 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0server-id = 2

以下几个需要修改的(保存文件为 mysqld.cnf) 
server-id = 2

写好后 执行复制到docker的命令:

docker cp ./mysqld.cnf some-mysql1:etc/mysql/mysql.conf.d/

5.重启2个主从数据库

docker restart some-mysql1

docker restart some-mysql2

6.配置从数据库

 1.查看主数据库的信息 show master status

2.进入到从数据库后执行

change master to master_host='192.168.2.77',master_port=33061,master_user='root',master_password='123456',master_log_file='binlog.000006',master_log_pos=1338;START SLAVE;show slave STATUS;

记得替换  master_log_file 和 master_log_pos

3.在从数据库执行下查看 

其中:Slave_IO_Running 与 Slave_SQL_Running都是Yes则说明主从配置成功!

4.大功告成 来点语句测下

create database if not exists xl_game3;use xl_game3;-- 玩家用户数据
DROP TABLE IF EXISTS `player_data`;
CREATE TABLE IF NOT EXISTS `player_data` (`uid` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'uid',`account` varchar(500) NOT NULL COMMENT '账号',`password` varchar(500) COMMENT '密码',`player_status` varchar(10) DEFAULT "0" COMMENT '状态 0:正常 1黑名单',`data` mediumtext CHARACTER SET utf8mb4 COMMENT '数据',PRIMARY KEY (`uid`),UNIQUE KEY `account` (`account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='玩家用户数据';

主数据库执行 

从数据库查看

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/292030.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

YACS(上海计算机学会竞赛平台)三星级挑战——牛奶供应(一)

题目描述 有一家牧场每天都会产出牛奶,在第 i 天,牛奶的产量为p[i]​。生产的牛奶可以卖到市场上,在第 i 天,市场需求为 c[i]​。如果市场需求不大,卖不掉牛奶,则多余的牛奶就会放进冷库保存。牛奶有一个保…

PyGame实现打砖块游戏

文章目录 砖块实现小车小球初始化和主循环 打砖块也是一个非常经典的小游戏,玩法大致如下,用一个小车接一个小球,然后反射小球,使之打在砖块上,当小球碰到砖块之后,则砖块被消掉,逻辑十分清晰。…

EDA实验-----直流电机驱动设计(Quartus II )

目录 一、实验目的 二、实验仪器设备 三、实验的重点和难点 四、实验原理 五、实验步骤 六、实验报告 七、实验过程 1.分频器代码 2.方向选择器 3.直流电动机工作原理 4.电路连接图 5.文件烧录 一、实验目的 了解直流电机控制的工作原理和实现的方法。掌握PWM波控…

linux下的进程组与会话的区别

进程组(Process Group)和会话(Session)是Unix/Linux操作系统中的两个概念,它们之间有一些关键区别: 定义和范围:一个进程组是一组相关进程的集合,它们具有相同的进程组ID&#xff08…

使用【OpenI启智平台】进行模型训练

前言 启智平台OpenI是一个人工智能开源开放平台,提供免费GPU算力可以进行模型训练。模式是git进行项目管理,可以创建调试任务调试代码以及保存镜像,创建训练任务训练模型,也提供推理和评测,我没用过就不讲述了。后来我…

Day67力扣打卡

打卡记录 美丽塔 II(前缀和 单调栈) 链接 class Solution:def maximumSumOfHeights(self, maxHeights: List[int]) -> int:n len(maxHeights)stack collections.deque()pre, suf [0] * n, [0] * nfor i in range(n):while stack and maxHeights…

嵌入式中断理解

一、概念 中断: 在主程序运行过程中,出现了特定的中断触发条件(中断源),使得CPU暂停当前正在运行的程序,转而去处理中断程序,处理完成后又返回原来被暂停的位置继续运行。 中断优先级&#x…

微信小程序-textarea组件字数实时更新

一、前言 本文实现的是在小程序中&#xff0c;textarea文本框输入文字后&#xff0c;实时显示文字的字数&#xff0c;获取更好的用户输入体验以及提示。 下图是实现的效果 二、代码实现 2-1、wxml代码 <view style"padding: 30rpx;"><view style"…

vue中监听Form表单值的变化

想要监听From表单中某个值的变化需要用到vue中的 watch watch: {inputForm.isHeating() {this.inputForm.otherHeating}}, isHeating是表单中的某个值&#xff0c;如果他变化就会清空另一个值

Python:正则表达式---贪婪匹配

在正则表达式中&#xff0c;贪婪匹配是指匹配尽可能多的字符&#xff0c;而非贪婪匹配&#xff08;也称为懒惰匹配或最小匹配&#xff09;则是匹配尽可能少的字符。 .* 表示匹配任意数量的任意字符&#xff08;除换行符外&#xff09;。贪婪匹配会将尽可能多的字符都作为匹配结…

以存算一体芯片加速汽车智能化进程,后摩智能带来更优解?

汽车产业的长期价值锚点已悄然变化&#xff0c;催生出新的商业机遇。 过去&#xff0c;在燃油车市场&#xff0c;燃油经济性和品牌认知度等是重要的消费决策因素和资本价值衡量标准&#xff0c;但在新能源时代&#xff0c;产业价值聚焦在两方面&#xff0c;一是电动化&#xf…

使用 Docker 部署企业培训系统 PlayEdu

1&#xff09;PlayEdu 介绍 官网&#xff1a;https://www.playedu.xyz/ GitHub&#xff1a;https://github.com/PlayEdu/PlayEdu PlayEdu 是一款适用于搭建内部培训平台的开源系统&#xff0c;旨在为企业/机构打造自己品牌的内部培训平台。PlayEdu 基于 Java MySQL 开发&…