mysql主从同步原理错误bug_mysql主从同步原理及错误解决

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

一切正常。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 错误1049(42000):未知数据库。 这个错误通常是由于尝试访问不存在的数据库而引起的。请确保您输入的数据库名称正确,并且该数据库已经存在于您的系统中。如果数据库不存在,请创建它并确保您有访问权限。 ### 回答2: 在使用MySQL时,可能会遇到"error 1049 (42000): unknown database"错误。这个错误说明MySQL服务器无法找到指定的数据库。 出现这个错误的原因可能是: 1. 数据库名字拼写错误。 当使用"USE"命令连接数据库时,输入的数据库名字必须准确无误。如果拼写错误MySQL就无法找到对应的数据库。 2. 数据库没有创建。 如果尝试连接的数据库还没有被创建,那么MySQL服务器就无法找到该数据库。在这种情况下,需要先通过“CREATE”命令创建一个新的数据库。 3. 数据库拒绝连接。 如果MySQL服务器无法连接到指定的数据库,就会提示这个错误。可能是因为数据库服务器挂掉了,或者是防火墙阻止了MySQL服务器的连接。 4. 数据库没有授权。 MySQL服务器可能会拒绝连接到指定的数据库,因为当前用户没有访问该数据库的授权。需要通过“GRANT”命令给用户授权,才能访问该数据库。 总的来说,出现"error 1049 (42000): unknown database"错误的原因是非常多的。需要仔细检查语句和相关权限,找到实际的问题所在,才能解决这个错误。 ### 回答3: 当我们在使用MySQL的时候,经常会遇到一些错误信息,其中比较常见的错误就是“error 1049 (42000): unknown database”,该错误信息在我们使用MySQL语句操作数据库时,经常出现在我们创建或者查询数据库时。 这个错误提示意味着在我们进行操作的时候,发现了一个未知的数据库。在MySQL中,每一个数据库都必须明确地存在,否则我们就无法通过语句来访问它。 那么,为什么会出现这个错误? 首先,我们需要检查我们的MySQL命令是否正确。如果我们输入了错误的命令,或者命令拼写错误,那么就会出现错误信息。我们需要检查我们的命令,确保命令语法正确,正确的命令格式应该是:CREATE DATABASE database_name; 其次,我们需要检查我们的MySQL用户权限。如果我们的用户没有足够的访问权限,那么就会出现“unknown database”错误。我们需要检查我们的权限,如果需要的话,可以使用GRANT语句授予用户更多的权限。 最后,我们需要确认我们要操作的数据库是否存在。如果我们要创建一个新的数据库,在执行语句之前,需要确认我们输入的数据库名称是正确的,数据库名称不要包含空格或特殊字符。 如果我们仍然无法解决error 1049”的问题,我们可以进行一些简单的调试。我们可以通过连接到MySQL的控制台,查看我们的用户权限和数据库列表,进一步查明导致错误的原因。我们也可以检查MySQL日志文件,查看详细的错误信息,帮助我们解决问题。 总之,“error 1049 (42000): unknown database”错误MySQL中常见的错误之一,通常是由于语法错误、权限问题或数据库不存在引起的。通过仔细检查MySQL命令、用户权限和数据库名称,我们可以快速解决这个问题,并正确地使用MySQL进行数据库操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值