mysql5.6数据库同步,单向双向同步问题
windows下MySQL5.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数据库同步,单向双向同步问题的更多相关文章
- Oracle主从同步、双向同步的配置
(本教程展示了Windows环境的oracle数据库主从同步,Linux环境一样也可以) (把主数据库obpm 和从数据库orcl 用实际的数据库名给替换掉) (配置主从同步后,再配置双向同步,可能会 ...
- mysql 之 主从同步(单向同步和双向同步)
一. 实验环境部署 主服务器(MySQL-01) IP: 192.168.8.241 端口3306 ,操作系统:Centos6.5 64位 从服务器(MySQL-02) IP: 192.168. ...
- SymmetricDS 数据库双向同步开源软件入门
一句话概括该软件:SymmetricDS是一个文件和数据库同步软件,开源的,支持多主复制,同步时过滤和在异构的网络环境中进行数据转换传输.它支持单向和双向上的多个订阅者,异步的数据复制. 以下是从CS ...
- MySQL 数据库双向同步复制
MySQL 复制问题的最后一篇,关于双向同步复制架构设计的一些设计要点与制约. 问题和制约 数据库的双主双写并双向同步场景,主要考虑数据完整性.一致性和避免冲突.对于同一个库,同一张表,同一个记录中的 ...
- windows下 MySQL数据库双向同步 配置步骤
最近在项目中遇到了要实现服务器上MySql数据双向同步,在网上找了很多资料,但是大部分都是在liux系统下配置的, 而且都是互相转载,没有一个详细的步骤,于是决定写一个windows系统下 ...
- 文件同步 单向rsync 双向unison 监控inotifywait 免密登录
1.负载均衡中文件同步必不可少,我这边选择rsync来实现文件同步 rsync同步文件机制更适用于单向文件同步,可配合unison实现双向同步功能. 实现同步的两种方法 一:ssh方法 rsync - ...
- MYSQL单双向同步
Master:192.168.1.101 Slave :192.168.1.102 单向同步(一) 进入Master启动MYSQL [root@localhost ~]# service mysql ...
- MySQL主从双向同步复制
本文介绍了mysql主从,实现mysql的双向同步复制. MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护日 ...
- ogg的安装配置 配置双向同步(含DDL)
第一部分 先配置单向同步(含DDL) 一 源端安装GoldenGate 创建用户 创建目录 mkdir -p /opt/ogg chmod -R 777 /opt/ogg chown -R oracl ...
随机推荐
- Android Weekly Notes Issue #319
Android Weekly Issue #319 July 22nd, 2018. Android Weekly Issue #319 本期内容包括: MotionLayout加动画; Kotlin ...
- myBatis 如何接受 返回count(*),sum()得到的int值
<select id="selectRemainder" resultType="java.lang.Integer"> SELECT SUM(aw ...
- 反向ssh
参考 https://www.thegeekstuff.com/2013/11/reverse-ssh-tunnel/ https://www.howtoforge.com/reverse-ssh-t ...
- OpenCv-Python 图像处理基本操作
1. 图片加载.显示和保存 import cv2 img = cv2.imread("01.jpg") imgGrey = cv2.imread("01.jpg" ...
- PS 滤镜— — 镜头光晕
clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...
- BZOJ_2259_ [Oibh]新型计算机 _最短路
Description Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算机的输入也很独特,假 ...
- RT-Thread的线程(任务)处理 rt_thread_create/rt_thread_init区别
RT-Thread中使用线程这个概念,而不是任务.两者相似,我在这里把他的线程当作任务来理解了 1.任务处理: 动态任务相关API 创建任务:rt_thread_create函数,创建任务之后会返回r ...
- kkkk
monkey -p com.alfl.www -v -v -v --throttle 50 --pct-touch 30 --pct-motion 15 --pct-nav 15 --pct-ma ...
- python2 + selenium + eclipse 中,通过django生产数据库表的时候报错
python2 + selenium + eclipse 中,通过django生产数据库表的时候报错 解决: 1.查看自己电脑中,“开始-->控制面板-->管理工具-->服务--&g ...
- iview组件DatePicker type="datetimerange绑定初始默认时间值
使用::value="[this.startTime,this.endTime]",绑定当天时间 如下: <DatePicker type="datetimeran ...