Linux---MySQL主從配置相關報錯合集

mysql 數據同步 出現Slave_IO_Running:No或者Slave_Sql_Running:No問題的解決方法小結

mysql主從複製經常會遇到錯誤而導致slave端複製中斷這個時候一般就需要人工干預跳過錯誤才能繼續。



如果是slave_io_running no了那麼就我個人看有三種情況一個是網絡有問題連接不上第二個是有可能my.cnf有問題配置文件怎麼寫就不說了網上太多了最後一個是授權的問題slave上沒有權限讀master上的數據replication slave和file權限是必須的。

一旦io爲no了先看err日誌看看報什麼錯很可能是網絡也有可能是包太大收不了這個時候主備上改max_allowed_packet這個參數。 max_allowed_packet=1024M 可在 vi /etc/my.cnf中的[mysqld]中添加

如果是slave_sql_running no了那麼也有兩種可能一種是slave機器上這個表中出現了其他的寫操作就是程序寫了這個是會有問題的還有一種佔絕大多數可能的是slave進程重啓事務回滾造成的這也是mysql的一種自我保護的措施像關鍵時候只讀一樣。



跳過錯誤有兩種方式

1.跳過指定數量的事務

mysql>slave
stop;
mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1        #跳過一個事務
mysql>slave start


其中SQL_SLAVE_SKIP_COUNTER=N;再開一下slave就可以了這個全局變量賦值爲N的意思是 

 

This statement skips the next N events from the master. This is useful for recovering from replication stops caused by a statement. 

 

This statement is valid only when the slave thread is not running. Otherwise, it produces an error. 



2.修改mysql的配置文件通過slave_skip_errors參數來跳所有錯誤或指定類型的錯誤

vi /etc/my.cnf
[mysqld]
slave-skip-errors=1062,1053,1146 #跳過指定error no類型的錯誤
slave-skip-errors=all #跳過所有錯誤


相關錯誤實例


1、出現錯誤提示、

 

 

Slave I/O: error connecting to master '[email protected]:3306' - retry-time: 60  retries: 86400, Error_code: 1045

解決方法

檢查網絡密碼以及權限相關的設置是否有誤


 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='211.103.156.198',

 master_user='mysql, 

 master_password='password

 master_port=3306, 

 master_log_file='mysql-bin.000025', 

 master_log_pos=1010663436;



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='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;


 8、錯誤提示如下

Error
reading packet from server:
 
Access denied; you need the REPLICATION SLAVE privilege for this operation (
server_errno=1227)


 

【解決辦法】主服務器給的複製權限不夠重新賦予權限。

 
>
grant replication slave on *.* to 'mysql'@'master IP' identified by 'password'
>
flush privileges


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章