windowsMySQL5.6实现主从数据库同步数据

  mysql5.6数据库同步,单向双向同步问题

.单向同步

主数据库(mysql5.6)192.168.1.104

从数据库(mysql5.6)192.168.1.105

略去创建库的步骤,这里认为你同步的数据库已经存在,而且主从数据库的库和表结构均相同

1.在主数据库上创建用户

insert into mysql.user(host,user,password)

values('localhost','admin',password('123456'));

flush privileges;

2.主数据库提供用户,赋值访问权限

仅仅192.168.1.105这个机器使用admin/123456同步

grant replication slave,reload,super on *.* to 'admin'@'192.168.1.105' identified by '123456' with grant option;

所有人都只用admin/123456同步

grant replication slave,reload,super on *.* to 'admin'@'%' identified by '123456' with grant option;

3.修改104主数据库的my.ini

在[mysqld]节点下配置一下代码

#设置服务器id,为1表示主服务器,注意:如果原来的配置文件中已经有这一行,就不用再添加了。

server_id=1

log_bin=mysql-bin  #启动MySQ二进制日志系统,注意:如果原来的配置文件中已经有这一行,就不用再添加了。

binlog_do_db=test  #需要同步的数据库名,如果有多个数据库,可重复此参数,每个数据库一行

binlog_ignore_db=mysql  #不同步mysql系统数据库

binlog_ignore_db=information_schema  #不同步information_schema系统数据库

然后保存my.ini配置文件

管理员打开cmd

先停止mysql服务,net stop mysql

然后重启mysql服务,net start mysql

服务启动成功后,登陆mysql

mysql -u root -p123456  注意,-p和123456之间不用空格

在查看主数据库的状态,show master status\G;

+------------------+----------+--------------+------------------+
|
File                        |
Position  | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |    120      | test            |
mysql                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

注意:这里记住File的值:mysql-bin.000001和Position的值:120,后面会用到。

4.修改105从数据库的my.ini文件

server_id=2

log_bin=mysql-bin

replicate_do_db=test

replicate_ignore_db=mysql

replicate_ignore_db=information_schema

保存my.ini

然后停止mysql服务,net stop mysql

在启动mysql服务,net start mysql

然后进入mysql -u root -p123456

先停止从数据库同步,stop slave,

再输入:change master to master_host='192.168.1.104',master_user='admin',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=120;
#执行同步语句

开启同步,start slave

注:经测试,stop slave ,start slave 和 slave start,slave stop一样都可以,

最后查看一下状态:show slave status;

mysql>
show slave status\G;

***************************
1. row ***************************

Slave_IO_State: Waiting for
master to send event

Master_Host: 192.168.1.104

Master_User: test01

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 120

Relay_Log_File: mysql-bin.000001

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000001

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:
mysql,information_schema

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 120

Relay_Log_Space: 465

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert:
No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID:
f44dc946-f462-11e4-81cc-00ffb613a054

Master_Info_File:
D:\GreenProgramFiles\MySQL Server 5.6\data\master

.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read
all relay log; waiting for the sla

ve
I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1
row in set (0.00 sec)

注:Slave_IO_Running: Yes

Slave_SQL_Running: Yes

这两个都是yes的时候同步才会成功发生,否则不能实现同步

5.最后在主数据库上执行插入,更改,删除语句,在从数据库上查看,数据保持一致了,

.双向同步

在上述配置保持不变的情况下,各自增加主从配置项

104:主数据库已经配置完毕,需要配置从数据库

log_bin=mysql-bin

replicate_do_db=test

replicate_ignore_db=mysql

replicate_ignore_db=information_schema

重启mysql,登陆后输入:

stop
slave;

change
master to master_host='192.168.1.105',master_user='admin',master_password='123456',master_log_file='mysql-bin.0000001',master_log_pos=120;

# master_log_file='mysql-bin.0000001',master_log_pos=120;

其中这两个参数是根据master主数据库的二进制日志文件和为止固定的

start
slave;

show
slave status\G;

105:从数据库已经配置完毕,需要配置主数据库

log_bin=mysql-bin

binlog_do_db=test

binlog_ignore_db=mysql

binlog_ignore_db=information_schema

重启mysql,登陆输入:

flush
tables with read lock;

show
master status\G;得到主数据库的信息

根据这这个命令的结果在跟新104主从数据库的同步日志和位置

mysql>change
master to master_log_file='mysql-bin.00002',master_log_pos=120;

同时要为用户开放权限

仅仅192.168.1.105这个机器使用admin/123456同步

grant
replication slave,reload,super on *.* to 'admin'@'192.168.1.105' identified by
'123456' with grant option;

所有人都只用admin/123456同步

grant
replication slave,reload,super on *.* to 'admin'@'%' identified by '123456'
with grant option;

GRANT
REPLICATION SLAVE ON *.* TO 'admin'@'%' IDENTIFIED BY '123456';

GRANT
FILE,SELECT,REPLICATION SLAVE ON *.* TO 'admin'@'%' IDENTIFIED BY '123456';

最后配置完毕的结果

104:
主从数据库

#主数据库配置项

server_id=1

#auto_increment_increment=2

#auto_increment_offset=1

log_bin=mysql-bin

binlog_do_db=test

binlog_ignore_db=mysql

binlog_ignore_db=information_schema

#从数据库配置项

replicate_do_db=
test #同步的数据库

replicate_ignore_db=mysql

replicate_ignore_db=information_schema

105:主从数据库

#从数据库配置项

server_id=2

#auto_increment_increment=2

#auto_increment_offset=1

log_bin=mysql-bin

replicate_do_db=
test #同步的数据库

replicate_ignore_db=mysql

replicate_ignore_db=information_schema

#主数据库配置项

binlog_do_db=test

binlog_ignore_db=mysql

binlog_ignore_db=information_schema

遇到的问题总结:

1.经测试,主mysql5.6,从mysql5.5,不能实现同步,

Slave_IO_Running:
No

Slave_SQL_Running:
Yes

错误提示:Last_IO_Error: Got fatal error 1236 from master when  reading data from binary log:

问题:一般版本不一致

2.

Slave_IO_Running: Yes

Slave_SQL_Running: No

3. Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for

replication to work.

mysql>show variables like ‘server_id';

+—————+——-+
| Variable_name | Value |
+—————+——-+
| server_id | 3 |
+—————+——-+

主从并不一样,排除该问题。

找到原因在于,拷贝整个data目录,把auto.cnf文件也拷贝过来了,里面记录了数据库的uuid,每个库的uuid应该是不一样的。

[auto]
server-uuid=6dcee5be-8cdb-11e2-9408-90e2ba2e2ea6

解决办法,按照这个16进制格式,随便改下,重启mysql即可。

4. 111010 17:35:49 [ERROR] Error reading packet from server: Client
requested master

to start replication from impossible position
( server_errno=1236)

111010
17:35:49 [ERROR] Slave I/O: Got fatal error 1236 from master when reading data

from
binary log: 'Client requested master to start replication from impossible

position',
Error_code: 1236

111010
17:35:49 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.000288',

position
627806304

解决方法:

mysql>
stop slave;

mysql>
change master to master_log_file='mysql-bin.000288',master_log_pos=627625751;

mysql>
start slave;

5.在一台主机上配置一台从机,启动的时候报
ERROR 1872 (HY000): Slave failed to initialize relay log info structure
from the

repository(双向配置后,启动从机报错)

解决方法:配置relay_log=relay-,

然后再重新停止net stop mysql,

启动net start mysql,

登陆mysql -u root -p123456

运行reset slave

然后启动从机start slave

mysql5.6数据库同步,单向双向同步问题的更多相关文章

  1. Oracle主从同步、双向同步的配置

    (本教程展示了Windows环境的oracle数据库主从同步,Linux环境一样也可以) (把主数据库obpm 和从数据库orcl 用实际的数据库名给替换掉) (配置主从同步后,再配置双向同步,可能会 ...

  2. mysql 之 主从同步(单向同步和双向同步)

    一. 实验环境部署 主服务器(MySQL-01) IP: 192.168.8.241  端口3306  ,操作系统:Centos6.5 64位 从服务器(MySQL-02)  IP: 192.168. ...

  3. SymmetricDS 数据库双向同步开源软件入门

    一句话概括该软件:SymmetricDS是一个文件和数据库同步软件,开源的,支持多主复制,同步时过滤和在异构的网络环境中进行数据转换传输.它支持单向和双向上的多个订阅者,异步的数据复制. 以下是从CS ...

  4. MySQL 数据库双向同步复制

    MySQL 复制问题的最后一篇,关于双向同步复制架构设计的一些设计要点与制约. 问题和制约 数据库的双主双写并双向同步场景,主要考虑数据完整性.一致性和避免冲突.对于同一个库,同一张表,同一个记录中的 ...

  5. windows下 MySQL数据库双向同步 配置步骤

          最近在项目中遇到了要实现服务器上MySql数据双向同步,在网上找了很多资料,但是大部分都是在liux系统下配置的, 而且都是互相转载,没有一个详细的步骤,于是决定写一个windows系统下 ...

  6. 文件同步 单向rsync 双向unison 监控inotifywait 免密登录

    1.负载均衡中文件同步必不可少,我这边选择rsync来实现文件同步 rsync同步文件机制更适用于单向文件同步,可配合unison实现双向同步功能. 实现同步的两种方法 一:ssh方法 rsync - ...

  7. MYSQL单双向同步

    Master:192.168.1.101 Slave  :192.168.1.102 单向同步(一) 进入Master启动MYSQL [root@localhost ~]# service mysql ...

  8. MySQL主从双向同步复制

    本文介绍了mysql主从,实现mysql的双向同步复制. MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护日 ...

  9. ogg的安装配置 配置双向同步(含DDL)

    第一部分 先配置单向同步(含DDL) 一 源端安装GoldenGate 创建用户 创建目录 mkdir -p /opt/ogg chmod -R 777 /opt/ogg chown -R oracl ...

随机推荐

  1. Spring Boot2.0之性能优化

    1.JVM参数调优   针对运行效果  吞吐量    初始堆内存与最大堆尽量相同   减少垃圾回收次数  2.扫包优化: 启动优化 默认Tomcat容器改为Undertow Tomcat的吞吐量500 ...

  2. BZOJ 1231 [Usaco2008 Nov]mixup2 混乱的奶牛:状压dp + 滚动数组

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1231 题意: 给你n个数字s[i],问你有多少个排列,使得任意相邻两数字之差的绝对值大于m ...

  3. 使用chrome的F12开发人员工具进行网页前端性能测试

    用chrome访问被测网站,定位到你要测试的动作所在页面或被测页面的前一页.按F12调出开发人员工具,其它的功能我就不介绍了,直接切换到性能选项卡Profiles. 点击start,生成ProFile ...

  4. Linux下查找进程,kill进程

    1. ps命令用来查找linux运行的进程,常用命令: ps aux | grep 进程名:  eg:ps aux | grep admin 查找admin的进程 或者 ps -ef | grep j ...

  5. 监听输入框变化(oninput,onpropertychange,onchange)

    oninput,onpropertychange,onchange: oninput是onpropertychange的非IE浏览器版本,支持firefox和opera等浏览器,但有一点不同,它绑定于 ...

  6. skynet实践(9)-随机数重复问题

    最近在使用skynet的过程中,遇到需要为玩家的每次请求产生一个随机序列的场景.简化如下: main.lua中每隔1S便发出一次随机数请求: local skynet = require " ...

  7. FFmpeg命令:几种常见场景下的FFmpeg命令(摄像头采集推流,桌面屏幕录制推流、转流,拉流等等)

    前提: 首先你得有FFmpeg(ffmpeg官网快捷通道:http://ffmpeg.org/) 再者,推流你得有个流媒体服务,个人测试用小水管:rtmp://eguid.cc:1935/rtmp/t ...

  8. 洛谷 P4238 [模板] 多项式求逆

    题目:https://www.luogu.org/problemnew/show/P4238 看博客:https://www.cnblogs.com/xiefengze1/p/9107752.html ...

  9. raid0和raid5的 实验过程

    raid:独立的磁盘冗余阵列 创建raid0: 环境准备:准备三块大小相同的磁盘或分区,此处要特别注意:红色字体 [root@localhost6 home]#fdisk /dev/sdd ##对/d ...

  10. c++常用函数STL

    完c++快一年了,感觉很有遗憾,因为一直没有感觉到c++的强大之处,当时最大的感觉就是这个东西的输入输出比C语言要简单好写. 后来我发现了qt,opencv,opengl,原来,c++好玩的狠. 在这 ...