mysql主从同步的原理:

1、在master上开启bin-log日志功能,记录更新、插入、删除的语句。

2、必须开启三个线程,主上开启io线程,从上开启io线程和sql线程。

3、从上io线程去连接master,master通过io线程检查有slave过来的请求,请求日志、postsion位置。

4、master将这些相应的日志返回给slave,slave自己去下载到本地的realy_log里面,写入一个master-info日志记录同步的点。

5、slave的sql线程检查到realy-log日志有更新,然后在本地去exec执行。

一:

Slave I/O: error connecting to master 'backup@192.168.1.x:3306' - retry-time: 60  retries: 86400, Error_code: 1045

解决方法

从服务器上删除掉所有的二进制日志文件,包括一个数据目录下的master.info文件和hostname-relay-bin开头的文件。

master.info::记录了Mysql主服务器上的日志文件和记录位置、连接的密码。

或者是防火墙问题

二:出现错误提示

Error reading packet from server: File '/home/mysql/mysqlLog/log.000001' not found (Errcode: 2) ( server_errno=29)

解决方法:

由于主服务器运行了一段时间,产生了二进制文件,而slave是从log.000001开始读取的,删除主机二进制文件,包括log.index文件。

三:错误提示如下

Slave SQL: Error 'Table 'xxxx' doesn't exist' on query. Default database: 't591'. Query: 'INSERT INTO `xxxx`(type,post_id,browsenum)

SELECT type,post_id,browsenum FROM xxxx WHERE hitdate='20090209'', Error_code: 1146

解决方法:

由于slave没有此table表,添加这个表,使用slave start 就可以继续同步。

四:错误提示如下

Error 'Duplicate entry '1' for key 1' on query. Default database: 'movivi1'. Query: 'INSERT INTO `v1vid0_user_samename`

VALUES(null,1,'123','11','4545','123')'

Error 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

to use near '' at line 1' on query. Default database: 'club'. Query: 'INSERT INTO club.point_process ( GIVEID, GETID, POINT, CREATETIME, DEMO )

VALUES ( 0, 4971112, 5, '2010-12-19 16:29:28','

1 row in set (0.00 sec)

Mysql > Slave status\G;

显示:Slave_SQL_Running 为 NO

解决方法:

Mysql > stop slave;

Mysql > set global sql_slave_skip_counter =1 ;

Mysql > start slave;

五:错误提示如下

show slave status\G;

Master_Log_File: mysql-bin.000029

Read_Master_Log_Pos: 3154083

Relay_Log_File: c7-relay-bin.000178

Relay_Log_Pos: 633

Relay_Master_Log_File: mysql-bin.000025

Slave_IO_Running: Yes

Slave_SQL_Running: No

Replicate_Do_DB: club

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 1594

Last_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are:

the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log),

the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log),

a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's

binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.

Skip_Counter: 0

Exec_Master_Log_Pos: 1010663436

这个问题原因是,主数据库突然停止或问题终止,更改了mysql-bin.xxx日志,slave服务器找不到这个文件,需要找到同步的点和日志文件,然后chage master即可。

解决方法:

change master to

master_host='IP',

master_user='同步帐号',

master_password='同步密码',

master_port=3306,

master_log_file='mysql-bin.000025',

master_log_pos=1010663436;

六:错误提示如下

Error 'Unknown column 'qdir' in 'field list'' on query. Default database: 'club'. Query: 'insert into club.question_del (id, pid,

ques_name, givepoint, title, subject, subject_pid, createtime, approve, did, status, intime, order_d, endtime,banzhu_uid,

banzhu_uname,del_cause,qdir) select id, pid, ques_name, givepoint, title, subject, subject_pid, createtime, approve, did,

status, intime, order_d, endtime,'1521859','admin0523','无意义回复',qdir from club.question where id=7330212'

1 row in set (0.00 sec)

这个错误就说club.question_del 表里面没有qdir这个字段 造成的加上就可以了~!

在主的mysql : 里面查询 Desc club.question_del;

在 错误的从服务器上执行 : alter table question_del add qdir varchar(30) not null;

七:错误提示如下

Slave_IO_Running: NO

这个错误就是IO 进程没连接上  ,想办法连接上把 把与主的POS 号和文件一定要对,然后重新加载下数据。具体步骤:

slave stop;

change master to master_host='IP地址',master_user='club',master_password='mima ',master_log_file='mysqld-bin.000048',MASTER_LOG_POS=396549485;

注:master_log_file='mysqld-bin.000048',MASTER_LOG_POS=396549485;是从主的上面查出 来的 :show master status\G;

LOAD DATA FROM MASTER;

load data from master;

slave start;

八 ,mysql报错如下:

mysql> show slave status\G;

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

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.0.198

Master_User: rootclub

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000061

Read_Master_Log_Pos: 494107148

Relay_Log_File: xyxyclub-relay-bin.006609

Relay_Log_Pos: 1073365

Relay_Master_Log_File: mysql-bin.000061

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB: club

Replicate_Ignore_DB:

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: 494107148

Relay_Log_Space: 1073365

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

1 row in set (0.00 sec)

ERROR:

No query specified  #这里提示有错误,刚开始我以为数据库的问题呢,经过查询验证,发现并不是数据库的问题,而是我们操作的问题,

看下面操作。就没有报错误吧。

mysql> mysql> show slave status\G

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

Slave_IO_State:

Master_Host: 192.168.0.198

Master_User: rootclub

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000061

Read_Master_Log_Pos: 494248077

Relay_Log_File: xyxyclub-relay-bin.006609

Relay_Log_Pos: 1213077

Relay_Master_Log_File: mysql-bin.000061

Slave_IO_Running: No

Slave_SQL_Running: No

Replicate_Do_DB: club

Replicate_Ignore_DB:

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: 494246860

Relay_Log_Space: 1214294

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: NULL

1 row in set (0.00 sec)

mysql>

解释:

show slave status\G

\G就是结束  再加一个";" 就多余了,所以才报错,这2个结束符号别重复使用就是...

九.mysql> show slave status\G

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

Slave_IO_State:

Master_Host: 192.168.1.18

Master_User: tongbu

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000022

Read_Master_Log_Pos: 106

Relay_Log_File: mysqld-relay-bin.000035

Relay_Log_Pos: 251

Relay_Master_Log_File: mysql-bin.000022

Slave_IO_Running: No

Slave_SQL_Running: No

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 1

Exec_Master_Log_Pos: 106

Relay_Log_Space: 552

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: NULL

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 1236

Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

Last_SQL_Errno: 0

Last_SQL_Error:

1 row in set (0.00 sec)

解决方法是在master端从新看一下master状态

在master那边,执行:

flush logs;

show master status;

记下File, Position。

在slave端,执行:

Slave stop

CHANGE MASTER TO MASTER_LOG_FILE='testdbbinlog.000008',MASTER_LOG_POS=107;

slave start;

show slave status \G

一切正常。

mysql主从同步原理及错误解决的更多相关文章

  1. windows 系统本地做mysql 主从同步,最后面解决主从同步库名不一致,表结构一致

    原文:windows 系统本地做mysql 主从同步,最后面解决主从同步库名不一致,表结构一致 mysql主从同步的好处以及原理       之前看到很多新闻说某某的服务器奔溃,磁盘碎了,导致数据丢失 ...

  2. Mysql 主从同步原理简析

    在开始讲述原理的情况下,我们先来做个知识汇总,究竟什么是主从,为什么要搞主从,可以怎么实现主从,mysql主从同步的原理1.什么是主从其实主从这个概念非常简单主机就是我们平常主要用来读写的服务,我们称 ...

  3. 高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏

    1. MySQL主从同步实现方式 MySQL主从同步是基于Bin Log实现的,而Bin Log记录的是原始SQL语句. Bin Log共有三种日志格式,可以binlog_format配置参数指定. ...

  4. MySQL主从同步原理 部署【转】

    一.主从的作用:1.可以当做一种备份方式2.用来实现读写分离,缓解一个数据库的压力二.MySQL主从备份原理master 上提供binlog ,slave 通过 I/O线程从 master拿取 bin ...

  5. mysql 主从 同步原理及配置

    一.在mssql 里头实现同步镜像,只能主库用而镜像库不能同时用,而mysql 主从同步可以实现 数据库的读写分离,主库负责 update insert delete ,从库负责select 这样一来 ...

  6. 架构师必备:MySQL主从同步原理和应用

    日常工作中,MySQL数据库是必不可少的存储,其中读写分离基本是标配,而这背后需要MySQL开启主从同步,形成一主一从.或一主多从的架构,掌握主从同步的原理和知道如何实际应用,是一个架构师的必备技能. ...

  7. MySQL主从同步原理

    mysql主从复制用途 实时灾备,用于故障切换 读写分离,提供查询服务 备份,避免影响业务 主从部署必要条件 主库开启binlo日志(设置log-bin参数) 主从server-id不同 从库可以连同 ...

  8. MySQL主从同步-原理&实践篇

    来源:Onegoleya 简栈文化 什么是mysql的主从复制? MySQL 主从复制是指数据可以从一个MySQL数据库服务器主节点复制到一个或多个从节点.MySQL 默认采用异步复制方式,这样从节点 ...

  9. Mysql主从同步原理简介

    1.定义:当master(主)库的数据发生变化的时候,变化会实时的同步到slave(从)库. 2.好处: 1)水平扩展数据库的负载能力. 2)容错,高可用.Failover(失败切换)/High Av ...

随机推荐

  1. 三十七.MySQL视图 MySQL存储过程

    1.视图的基本使用 把/etc/passwd文件的内容存储到db9库下的user表里 添加新字段id 存储记录的行号(在所有字段的前边) 创建视图v1 结构及数据user表的字段.记录一样. 创建视图 ...

  2. Java上传大文件夹

    javaweb上传文件 上传文件的jsp中的部分 上传文件同样可以使用form表单向后端发请求,也可以使用 ajax向后端发请求 1.通过form表单向后端发送请求 <form id=" ...

  3. 监控ntp进程的

    !#/bin/bash ntp_num=$[`ps -ef|grep ntp|wc -l`-1] if [ $ntp_num == 1 ];then echo 0 else echo $ntp_num ...

  4. 搭建自己的博客(十三):为博客后台添加ckeditor富文本编辑器

    使用django默认的编辑器感觉功能太少了,所以集成一下富文本编辑器. 1.安装和使用 (1).安装 pip install django-ckeditor (2).注册应用 在django的sett ...

  5. 常见的时间字符串与timestamp之间的转换 时间戳

    这里说的字符串不是一般意义上的字符串,是指在读取日期类型的数据时,如果还没有及时解析字符串,它就还不是日期类型,那么此时的字符串该怎么与时间戳之间进行转换呢? ① 时间字符串转化成时间戳 将时间字符串 ...

  6. 在vultr中安装k8s测试

    vultr 安装k8s *** 如果国内访问 k8s.gcr.io 很慢,或者无法访问 *** 在应用yaml文件创建资源时,将文件中镜像地址进行内容替换即可: 将k8s.gcr.io替换为 regi ...

  7. 如何在微信小程序中国引入fontawesome字体图标

    fontawesome官网地址:http://fontawesome.dashgame.com/ 一. 二. 下载之后的字体图标 找到 文件中的如下图.ttf文件 三. 在https://transf ...

  8. java大型互联网项目大流量高并发所需的技术

    互联网一般运行技术:webservice,jquery,访问量,缓存,数据安全等,JAVA后台就比较多了,不过,像这种大型的互联网项目,基本框架都有了,你需要做的就是熟悉业务,熟悉他们公司所用的框架, ...

  9. 5.linux 软件安装的三种方法

      一.linux 操作系统中 软件的分类 以及软件的安装     vmtools  调用了perl语言写的安装脚本去进行内核的升级安装  ./ xxxxx        源码包安装软件:GNU  使 ...

  10. rpm包和deb分别是什么?

    一.RMP 是 LINUX 下的一种软件的可执行程序,你只要安装它就可以了.这种软件安装包通常是一个RPM包(Redhat Linux Packet Manager,就是Redhat的包管理器),后缀 ...