一、安装多个mysql

参见:

https://blog.csdn.net/wrh_csdn/article/details/80198795

https://www.cnblogs.com/qjoanven/p/7898006.html

https://www.cnblogs.com/qq931399960/p/10186627.html

如博客说的,我解压安装文件两次,在同一台win下做两mysql实例的主从同步:

版本:mysql-5.6.17-winx64.zip

我没有采用:mysqld.exe --port=3307 --console 的方式启动多个实例,而是采用了注册服务的方式操作:

1,编辑my.ini文件,以其中一个my.ini文件为例子,另一个只需要修改一下port、basedir、datadir即可:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL. [Client]
port = 3307 [mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin # These are commonly set, remove the # and set as required.
server_id = 1
port = 3307
basedir = C:\Users\eddy\Desktop\win-eddy\mysql-5.6.17-winx64
datadir = C:\Users\eddy\Desktop\win-eddy\mysql-5.6.17-winx64\data #back_log = 600
#max_connections=2000
#max_connect_errors = 6000
#wait_timeout=605800 #tmp_table_size = 256M
#max_heap_table_size = 256M #default-storage-engine=MYISAM # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#default_time_zone=+08:00 [mysql]
default-character-set=utf8

2,初始化mysql,搜索cmd找到命令提示符,右键以管理员身份运行,进入bin目录, 主要是生成一些data目录等。。

mysqld --initialize --user=mysql --console

3,安装服务(两个,在不同目录下):

mysqld --install mysql3306
mysqld --install mysql3307

windows下生成了两个服务,可以运行regedit,进入注册表

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mysql3306

C:\Users\eddy\Desktop\win-eddy\3306\bin\mysqld --defaults-file=C:\Users\eddy\Desktop\win-eddy\3306\my.ini  mysql3306

同理,也修改一下mysql3307

到此,运行两个服务

net start mysql3306

net start mysql3307

4,初始化mysql的使用

https://blog.csdn.net/wzcyamadie/article/details/82699398

二、主从同步问题

参见:

https://blog.csdn.net/L_Mr_l/article/details/81485391

我以端口为3307 做了主,3306为从,

1,主mysql的my.ini配置:红色为添加项

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL. [Client]
port = 3307 [mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin # These are commonly set, remove the # and set as required.
server_id = 1
port = 3307
basedir = C:\Users\eddy\Desktop\win-eddy\mysql-5.6.17-winx64
datadir = C:\Users\eddy\Desktop\win-eddy\mysql-5.6.17-winx64\data
log-bin=mysql-bin
binlog-do-db=cms_main #back_log = 600
#max_connections=2000
#max_connect_errors = 6000
#wait_timeout=605800 #tmp_table_size = 256M
#max_heap_table_size = 256M #default-storage-engine=MYISAM # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#default_time_zone=+08:00 [mysql]
default-character-set=utf8

2,从mysql,my.ini配置,红色字体为必填

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL. [Client]
port = 3306 [mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin # These are commonly set, remove the # and set as required.
server_id =2
basedir = C:\Users\eddy\Desktop\win-eddy\3306
datadir = C:\Users\eddy\Desktop\win-eddy\3306\data
port = 3306 log-slave-updates
log-bin=mysqld-bin
innodb_force_recovery=0
#default-storage-engine=MYISAM
#replicate-ignore-table=mydb.test1146
#replicate-do-db = cms_main
log-slave-updates
replicate-rewrite-db = cms_main -> cms_test #back_log = 600
#max_connections=2000
#max_connect_errors = 6000
#wait_timeout=605800 #tmp_table_size = 256M
#max_heap_table_size = 256M [mysql]
default-character-set=utf8

如果配置没有问题的话,重启是没有问题的。

3,备份主mysql的表结构,和insert语句,方式和方法有很多,这是为了从mysql中执行主mysql下的sql语句,提醒一点的是,如果没有做这一步,在主服务器中,修改从服务器中没有同步的数据,从服务器是没有记录的,就是说,从服务器只检测  主服务器insert,和已经同步过来的数据的update。

4,在主服务器:

  4.1,连接主服务器 锁表   FLUSH TABLES WITH READ LOCK;这样防止在做的时候数据改变了,导致脏数据,也为了防止,影响后的流程,下面一部再说

4.2,SHOW MASTER STATUS;  执行该命令  这一步很关键,这也是为啥锁库的原因,执行这句命令一会有两个参数后面用,一个是File,一个是Position。一个是日志的名称,一个是日志的位置。下面在配置从服务器的时候会用到

5,在从服务器的操作:

  5.1执行sql语句:

stop SLAVE;
CHANGE MASTER TO MASTER_HOST = '127.0.0.1',
MASTER_PORT = 3306,
MASTER_USER = 'user01',
MASTER_PASSWORD = '123456',
MASTER_LOG_FILE = 'mysql-bin.000008',
MASTER_LOG_POS = 2817; start SLAVE; show slave status;

当,Slave_IO_Running 和 Slave_SQL_Running 显示Yes,说明,从服务器配置完毕了

  5.2 从服务器上执行主服务器上面备份的表结构和表执行语句。

修改主服务器上面的数据,从服务器上的数据也变更了。ok

三、一个主服务的多个数据库同步到从服务器的一个数据库

主服务只需要多配置一个  binlog-do-db=cms_main

从服务器只需要多配置一个 replicate-rewrite-db

同一台windows下配置安装多个mysql实例,实现主从同步的更多相关文章

  1. windows下手动安装 Apache+php+mysql

    PHP 为什么先说php,因为apache的配置要写入php的一些路径 http://php.net/downloads.php  选择windows donwload 选择Thread Safe的版 ...

  2. 在一台Linux服务器上安装多个MySQL实例(一)--使用mysqld_multi方式

    (一)MySQL多实例概述 实例是进程与内存的一个概述,所谓MySQL多实例,就是在服务器上启动多个相同的MySQL进程,运行在不同的端口(如3306,3307,3308),通过不同的端口对外提供服务 ...

  3. 一台Windows下配置多个Tomcat服务器

    上一篇博客<Windows下配置Tomcat服务器>讲了,如何在一台Windows机器上配置一个Tomcat服务器.这篇介绍一下如何在一台Windows机器上配置多个Tomcat. 第一步 ...

  4. windows下配置启动多个mysql服务

    查找配置做下记录 先安装mysql5.6,安装不在介绍 接下来配置启动另一个mysql服务, 1:先到服务里停止在运行的mysql服务 2:到mysql的安装目录下(默认安装目录在c:\Program ...

  5. windows下如何安装和启动MySQL

    1.下载,解压到自己喜欢的目录 2.配置环境变量.MYSQL_HOME,值为mysql的根目录:在path中添加%MYSQL_HOME%/bin目录. 3.向windows注册mysql服务.必须用管 ...

  6. .NetCore 分布式日志收集Exceptionless 在Windows下本地安装部署及应用实例

    自己安装时候遇到很多问题,接下来把这些问题写出来希望对大家有所帮助 搭建环境: 1.下载安装 java 8 SDK (不要安装最新的10.0) 并配置好环境变量(环境变量的配置就不做介绍了) 2.下载 ...

  7. MySQL8.0在Windows下的安装和使用

    前言 MySQL在Windows下有2种安装方式:1.图形化界面方式安装MySQL 2.noinstall方式安装MySQL.在这里,本文只介绍第二种方式:以noinstall方式安装MySQL,以及 ...

  8. Windows下pry安装和配置

    Windows下pry安装和配置 pry是一个增强型的交互式命令行工具,比irb强大. 有自动完成功能,自动缩进,有颜色.有更强大的调试功能. pry 安装很简单. 在终端输入: gem instal ...

  9. Python在windows下的安装与配置

    安装python 文件准备: A. python安装文件:我用的是python-3.4.3.amd64.msi: 安装很简单,直接双击点下一步即可: 配置环境变量,在windows系统变量中找到pat ...

随机推荐

  1. Linux系统一些常用命令(持续增加)

    这些命令什么的全是从网上找的,防止忘记,留下来备忘 1.linux服务器如何从另一台服务器拷东西:可以用scp命令scp user@remote.machine:/remote/path /local ...

  2. 实验十 ZStack 网状网络实验

    实验十 ZStack 网状网络实验[实验目的]1. 了解 ZigBee 网状网络结构2. 掌握构建网状网络的方法[实验设备]1. 装有 IAR 开发工具的 PC 机一台2. 实验箱一台3. CCDeb ...

  3. Buy or Build(UVa1151)

    如果枚举每个套餐,并每次都求最小生成树,总时间复杂度会很高,因而需要先求一次原图的最小生成树,则枚举套餐之后需要考虑的边大大减少了. 具体见代码: #include<cstdio> #in ...

  4. [USACO09HOL]假期绘画Holiday Painting

    观察到列数只有15,可以想到对于每一列维护一颗线段树 sum表示该区间与目标矩阵中该区间相同元素个数 lazy表示该区间应被修改成什么颜色 g即目标矩阵中该区间白色格子的个数 显然一个区间的sum=区 ...

  5. python excle写数据

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/4/24 10:30 # @File : Excle写.py # @Softw ...

  6. 记SCOI2019

    离精英体验营结束已两周的,要哭的要笑的现在也一定释怀了.是时候冷静分析一下这次的考试了.时间序虽然有流水账的嫌疑,但这毕竟是OI界的流行风气. day0 早上坐学校包的商务车去了电子科技大学.走在来过 ...

  7. bond-team

    nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": & ...

  8. Day 22 初识面向对象

    一.两种编程思想 1.面向过程编程 核心是'过程',过程指的是解决问题的步骤,就是先干什么再干什么 基于面向过程思想编写程序相当于写一条流水线,是一种机械式的思维方式 优点:解决问题的思路清晰,可以把 ...

  9. H5外包 微信小程序外包 小程序外包 就找北京动点开发团队

    长年承接微信小程序.微信公众号开发 全职的H5开发团队,开发过几十款微信小程序公众号案例 欢迎来电咨询 QQ:372900288 微信:liuxiang0884 TEL:13911652504

  10. 承接VR外包|AR外包|Unity3D外包|UE4外包(内附案例演示)

    北京团队长年承接VR/AR项目外包 咨询QQ:372900288  微信:liuxiang0884