mysql主從錯誤總結

1 、出現錯誤提示  
Slave I/O: error connecting to master 'backup@192.168.0.x:3306' -retry-time: 60  retries: 86400,Error_code: 1045

解決方法:
從服務器上刪除掉全部的二進制日誌文件,包括一個數據目錄下的master.info文件和hostname -relay-bin 開頭的文件 。
master.info: 記錄了Mysql主服務器上的日誌文件和記錄位置、鏈接的密碼 。
#rm -rf *.*
----------------------------------------------------------------------------------------------
2 、出現錯誤提示
Error reading packet from server: File '/home/mysql/mysqlLog/log.000001' not found (Errcode: 2) (server_errno=29)

解決方法:
因爲主服務器運行了一段時間,產生了二進制文件,而slave是從log.000001開始讀取的,刪除主機二進制文件,包括log.index文件。
----------------------------------------------------------------------------------------------
3 、錯誤提示以下
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就能夠繼續同步。
-----------------------------------------------------------------------------------------------
4 、錯誤提示以下  
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;
-----------------------------------------------------------------------------------------------
5 、錯誤提示以下
# 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='192.168.0.1',
 master_user='同步賬號',
 master_password='同步密碼',
 master_port=3306,
 master_log_file='mysql-bin.000002',
 master_log_pos=106;
-----------------------------------------------------------------------------------------------
6 、錯誤提示以下

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;
-----------------------------------------------------------------------------------------------
7 、錯誤提示以下
Slave_IO_Running: NO

這個錯誤就是IO進程沒鏈接上,想辦法鏈接上把與主的POS號和文件必定要對,而後從新加載下數據。
具體步驟:
slave stop;
change master to
master_host='IP地址',
master_user='backup',
master_password='123456',master_log_file='mysqld-bin.000008',MASTER_LOG_POS=396;
注:master_log_file='mysqld-bin.000008',MASTER_LOG_POS=396;是從主的上面查出來的:show master status\G;

LOAD DATA FROM MASTER;
load data from master;
slave start;
-----------------------------------------------------------------------------------------------
八、錯誤提示以下
使用mysqlbinlog進行分析日誌 包如下錯誤:

# mysqlbinlog --no-defaults mysql-bin.000488 > 488.sql
ERROR: Error in Log_event::read_log_event(): 'Found invalid event in binary log', data_len: 66, event_type: 19

這個錯誤是使用的mysqlbinlog的版本不正確
# whereis mysqlbinlog
mysqlbinlog: /usr/bin/mysqlbinlog

# /usr/bin/mysqlbinlog --no-defaults -V
/usr/bin/mysqlbinlog Ver 3.2 for redhat-linux-gnu at x86_64

# /usr/local/mysql/bin/mysqlbinlog --no-defaults -V
/usr/local/mysql/bin/mysqlbinlog Ver 3.3 for unknown-linux-gnu at x86_64

經過查詢果真發如今默認狀況下調用的是系統默認安裝的mysql中的mysqlbinlog,由於這個mysqlbinlog的版本和當前的bin_log的版本不能對應起來,因此不能處理,使用對應的mysqlbinlog工做正常


# /usr/local/mysql/bin/mysqlbinlog --no-defaults mysql-bin.000488 |more
   /*!40019 SET @@session.max_insert_delayed_threads=0*/;
   /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
   DELIMITER /*!*/;
   # at 4
   #120228 23:05:14 server id 1 end_log_pos 106 Start: binlog v 4, server v 5.1.41-log created 120228 23:05:14
   BINLOG '
   Ku1MTw8BAAAAZgAAAGoAAAAAAAQANS4xLjQxLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
   '/*!*/;
   # at 106
   #120228 23:05:14 server id 1 end_log_pos 181 Query thread_id=175240 exec_time=0 error_code=0

使用如下命令查看二進制文件後,能夠正確查看到內容:
/usr/local/mysql_dir/bin/mysqlbinlog /tmp/1.000001或者將/usr/bin/上的mysqlbinlog替換成/usr/local/mysql_dir/bin/下的也能夠,如cp /usr/local/mysql_dir/bin/mysqlbinlog /usr/bin/mysqlbinlog,替換成功後,再執行命令mysqlbinlog /tmp/1.000001
------------------------------------------------------------------------------------------------
九、解決ERROR 1146 (42S02): Table 'mysql.servers' doesn't exist問題

(1)使用mysqld_safe --skip-grant-tables 啓動數據庫
(2)使用mysql進入數據庫
(3)use mysql
(4)建立表 mysql.servers
CREATE TABLE mysql.servers (
Server_name char(64) NOT NULL,
Host char(64) NOT NULL,
Db char(64) NOT NULL,
Username char(64) NOT NULL,
Password char(64) NOT NULL,
Port int(4) DEFAULT NULL,
Socket char(64) DEFAULT NULL,
Wrapper char(64) NOT NULL,
Owner char(64) NOT NULL,
PRIMARY KEY (Server_name)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MySQL Foreign Servers table';
(5)flush privileges; 成功
-------------------------------------------------------------------------------------------------
十、因爲主服務器異外重啓, 致使從報錯, 錯誤以下:
show slave status錯誤:
mysql> show slave status\G
Master_Log_File: mysql-bin.000288
Read_Master_Log_Pos: 627806304
Relay_Log_File: mysql-relay-bin.000990
Relay_Log_Pos: 627806457
Relay_Master_Log_File: mysql-bin.000288
Slave_IO_Running: No
Slave_SQL_Running: Yes
Exec_Master_Log_Pos: 627806304
Relay_Log_Space: 627806663


......
Last_IO_Error:
Got fatal error 1236 from master when  reading
data from binary log:
'Client requested master to start  
replication from impossible position'
mysql錯誤日誌:

tail /data/mysql/mysql-error.log
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
按照習慣, 先嚐試必改position位置.

mysql> stop slave;mysql> change master to master_log_file='mysql-bin.000288',master_log_pos=627625751;mysql> start slave;
錯誤依舊, 接下來登錄到主服務器查看binlog日誌.
先按照錯誤點的標記去主服務器日誌中查找:

[root@db1 ~]# mysqlbinlog --start-position=627655136 /data/mysql/binlog/mysql-bin.000288
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#111010 13:31:19 server id 4 end_log_pos 106 Start: binlog v 4, server v 5.1.45-log
created 111010 13:31:19
# Warning: this binlog is either in use or was not closed properly.
BINLOG '
F1aTTg8EAAAAZgAAAGoAAAABAAQANS4xLjQ1LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
'/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
沒有看到這個位置.

[root@db1 ~]# mysqlbinlog /data/mysql/binlog/mysql-bin.000288 > test.txt

less text.txt
看最後一部分
# at 627625495
#111010 16:35:46 server id 1 end_log_pos 627625631 Query thread_id=45613333
exec_time=32758 error_code=0
SET TIMESTAMP=1318289746/*!*/;
delete from freeshipping_bef_update where part='AR-4006WLM' and code=''
/*!*/;
# at
627625631#111010 16:35:46 server id 1 end_log_pos 627625751
Query thread_id=45613333
exec_time=32758 error_code=0
SET TIMESTAMP=1318289746/*!*/;
delete from shippingFee_special where part='AR-4006WLM'
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
找到最接近錯誤標記627655136的一個position是627625631.

再回到slave機器上change master, 將postion指向這個位置.

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql>
change master to master_log_file='mysql-bin.000288',master_log_pos=627625631;
Query OK, 0 rows affected (0.06 sec)

mysql>
start slave;Query OK, 0 rows affected (0.00 sec)
再次查看

mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Queueing master event to the relay log
Master_Host: 192.168.21.105
Master_User: rep
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000289
Read_Master_Log_Pos: 25433767
Relay_Log_File: mysql-relay-bin.000003
Relay_Log_Pos: 630
Relay_Master_Log_File: mysql-bin.000289
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
主從同步正常了, 一樣的方法修復其它slave機器.
-----------------------------------------------------------------------------------------------
十一、在作MySQL主從複製時遇到個ERROR 1201 (HY000): Could not initialize master info structure .
出現這個問題的緣由是以前曾作過主從複製!

解決方案是:運行命令 stop slave;
成功執行後繼續運行 reset slave;
而後進行運行GRANT命令從新設置主從複製。
具體過程以下:
mysql> change master to master_host='192.168.0.1', master_user='backup', master_pass  
word='123456', master_log_file='mysql-bin-000002', master_log_pos=553;  
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log  
mysql> stop slave;  
Query OK, 0 rows affected, 1 warning (0.00 sec)  

mysql> reset slave;  
Query OK, 0 rows affected (0.00 sec)  

mysql> change master to master_host='192.168.0.1', master_user='backup', master_pass  
word='123456', master_log_file='mysql-bin-000002', master_log_pos=553;  
Query OK, 0 rows affected (0.11 sec)  
------------------------------------------------------------------------------------------------
十二、在沒有解鎖的狀況下中止slave進程:

    > stop slave;
ERROR 1192 (HY000): Can't execute the given command because you have active locked tables or an active transaction

1三、change master語法錯誤,落下逗號

mysql> change master to
   -> master_host='IP'
   -> master_user='USER',
   -> master_password='PASSWD',
   -> master_log_file='mysql-bin.000002',
   -> master_log_pos=106;
ERROR 1064 (42000): 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 'master_user='USER',
master_password='PASSWD',
master_log_file='mysql-bin.000002' at line 3

1四、在沒有中止slave進程的狀況下change master

mysql> change master to master_host=‘IP', master_user='USER', master_password='PASSWD', master_log_file='mysql-bin.000001',master_log_pos=106;
ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first

1五、A B的server-id相同:

Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids;
these ids must be different for replication to work (or the --replicate-same-server-id option must be used on
slave but this does not always make sense; please check the manual before using it).
查看server-id
mysql> show variables like 'server_id';
手動修改server-id
mysql> set global server_id=2; #此處的數值和my.cnf裏設置的同樣就行
mysql> slave start;

6)change master以後,查看slave的狀態,發現slave_IO_running 爲NO
須要注意的是,作完上述操做以後最後重啓mysql進程

mysql

相關文章
相關標籤/搜索