解決 mysql主從失敗

環境
Linux 系統:redhat as4.5
Mysql 版本:mysql 4.1.22

 

         星期一上班,就聽到 開發說一臺mysql數據庫down掉(此臺數據庫只做備份用)。連上系統,用ps -ef |grep mysql查看下進程,果真以個進程都沒有。那就重啓mysql服務,呀啓動不起來。就查看mysql的錯誤日誌。
InnoDB: Doing recovery: scanned up to log sequence number 0 48155
InnoDB: Last MySQL binlog file position 0 79, file name /var/log/mysql/updatelog.000006
100621  5:36:33  InnoDB: Flushing modified pages from the buffer pool...
100621  5:36:33  InnoDB: Started; log sequence number 0 48155
100621  5:36:34 [ERROR] /mysql/libexec/mysqld: Error writing file '/data/db2.ihome.com.pid' (Errcode: 28)
100621  5:36:34 [ERROR] Can't start server: can't create PID file: No space left on device

 

Number of processes running now: 0
100621 05:36:34  mysqld restarted
/mysql/libexec/mysqld: Error writing file './db2-slow.log' (Errcode: 28)
100621  5:36:34 [ERROR] Could not use db2-slow.log for logging (error 28). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
100621  5:36:34  InnoDB: Database was not shut down normally!

 

      哦原來磁盤空間滿了,使用df -h 查看下,存放data的目錄已經使用100%.進入data目錄查看。原來是一個備份數據庫文件在裏面佔用的了大量的磁盤空間。查看備份腳本原來是備份腳本里面的路徑寫錯了。修改路徑,把備份文件移動到備份目錄。啓動mysql服務正常啓動。
 

 

    使用命令登陸上mysql,發現主從已經不同步了。查看mysql的錯誤日誌得到
100621  9:32:21 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000023' at position 211845, relay log './db2-relay-bin.000013' position: 217010
100621  9:32:21 [ERROR] Error in Log_event::read_log_event(): 'read error', data_len: 112, event_type: 2
100621  9:32:21 [ERROR] Error reading relay log event: slave SQL thread aborted because of I/O error
100621  9:32:21 [ERROR] Slave: 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. Error_code: 0
100621  9:32:21 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000023' position 211845

 

 

首先想到嘗試着手動來解決主從同步。連接上數據庫
 
[root@db2 data]# mysql -u root -p
Enter password:      輸入密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 55 to server version: 4.1.12-log

 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql>stop slave ; #停掉slave 進程,手動 解決mysql主從時,需要先結束掉mysql slave。

mysql> change master to
mysql->MASTER_LOG_POS=211845
mysql ->MASTER_LOG_FILE = 'mysql-bin.000023';
mysql>start slave;
mysql>show slave status\G;
查看同步依然是不成功。繼續查看mysql 錯誤日誌
100621  9:41:35 [Note] Slave SQL thread initialized, starting replication in log 'binglog mysql-bin.000023' at position 211845, relay log './db2-relay-bin.000001' position: 4
100621  9:41:35 [Note] Slave I/O thread: connected to master '[email protected]:3306',  replication started in log 'binglog mysql-bin.000023' at position 211845
100621  9:41:35 [ERROR] Error reading packet from server: Could not find first log file name in binary log index file (server_errno=1236)
100621  9:41:35 [ERROR] Got fatal error 1236: 'Could not find first log file name in binary log index file' from master when reading data from binary log
100621  9:41:35 [ERROR] Slave I/O thread exiting, read up to log 'binglog mysql-bin.000023', position 211845

 

刪除掉data目錄下文件
db2-relay-bin.000001 
db2-relay-bin.index
master.info 
relay-log.info # 這些文件裏面存放着同步時的信息。
     然後重啓下mysql 服務,查看同步信息。問題依舊。然後 查看上次錯誤日誌 與此次的錯誤日誌。找不到 log文件,連接上主的mysql數據庫。查看mysql信息一切正常。
#mysqlbinlog --start-position=211845  mysql-bin.000023 > a.sql
把從 211845到現在不同步的二進制文件導入到一個文本文件裏面。然後使用scp 傳到從數據庫上
scp a.sql [email protected]:/    輸入密碼自動copy到mysql 從服務器上的根目錄下。
打開a.sql 查看最後一行的
然後到從數據庫上 停止mysql slave 服務。stop slave
使用#mysql -uuser -p passwd database < /a.sql #手動導入沒有同步的數據
導入完成之後 刪除掉 db2-relay-bin.000001  db2-relay-bin.index master.info  relay-log.info 這些文件。 使用
mysql>stop slave ;
mysql>change master to MASTER_LOG_POS = 155383248 MASTER_LOG_FILE = 'mysql-bin.000023';
Query OK, 0 rows affected (0.01 sec)
然後重啓mysql服務,service mysqld restart
啓動slave
mysql>start slave;
查看mysql主從狀態mysql>show slave status\G;
           Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
看到這兩行狀態爲Yes我心甚慰。看到這兩行爲Yes表示已經開始同步數據了。
   下面是CHANGE MASTER TO語法
CHANGE MASTER TO master_def[,master_def] ...
 
master_def:
      MASTER_HOST = 'host_name'
    | MASTER_USER = 'user_name'
    | MASTER_PASSWORD = 'password'
    | MASTER_PORT =port_num
    | MASTER_CONNECT_RETRY =count
    | MASTER_LOG_FILE = 'master_log_name'
    | MASTER_LOG_POS =master_log_pos
    | RELAY_LOG_FILE = 'relay_log_name'
    | RELAY_LOG_POS =relay_log_pos
    | MASTER_SSL = {0|1}
    | MASTER_SSL_CA = 'ca_file_name'
    | MASTER_SSL_CAPATH = 'ca_directory_name'
    | MASTER_SSL_CERT = 'cert_file_name'
    | MASTER_SSL_KEY = 'key_file_name'
    | MASTER_SSL_CIPHER = 'cipher_list'
可以更改從屬服務器用於與主服務器進行連接和通訊的參數。
MASTER_USER,MASTER_PASSWORD,MASTER_SSL,MASTER_SSL_CA,MASTER_SSL_CAPATH,MASTER_SSL_CERT,MASTER_SSL_KEY和MASTER_SSL_CIPHER用於向從屬服務器提供有關如何與主服務器連接的信息。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章