MySQL錯誤修復:Table xx is marked as crashed and last (automatic?) repair failed

scofiekd發表於2020-11-24

問題一 Table xx is marked as crashed and last (automatic?) repair failed

有開發找到我,說資料庫壞了,連不上資料庫,看了下 MySQL 的錯誤日誌,報錯如下:

Error: Table './db_name/table_name' is marked as crashed and last (automatic?) repair failed

修復

1、先停止 MySQL:service mysqld stop
2、進入到 MySQL 資料庫的檔案存放目錄,比如 cd /data/mysql_data/xx_db
然後執行如下命令:

myisamchk --safe-recover -f -r *.MYI

執行完成後,為了保險起見,我們要將檔案的許可權改回 MySQL 的執行賬號(自行檢視),比如 mysql:

chown -R mysql:mysql .

3、啟動 MySQL:service mysqld start
4、最後,執行再次自動修復優化命令即可解決:

mysqlcheck --auto-repair --optimize --all-databases -p密碼

問題二 /usr/local/mysql/bin/mysqld does not exist or is not executable.

]# /data/wapage/hhzk/mserver/mysql5713/bin/mysqld_safe  --defaults-file=/etc/my.cnf &
[1] 24527
]# 2020-11-23T10:36:45.803151Z mysqld_safe Logging to '/data/wapage/hhzk/mserver/mysql5713/data/qd01-tech2-rec-build001.ps.easou.com.err'.
2020-11-23T10:36:45.809116Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information

[1]+  Exit 1                  /data/wapage/hhzk/mserver/mysql5713/bin/mysqld_safe --defaults-file=/etc/my.cnf

說明:mysqld_safe啟動指令碼預設的從/usr/local/mysql目錄中讀取另外一個啟動指令碼mysqld,因為我的安裝目錄為/data/wapage/hhzk/mserver/mysql5713。所以找不到相關檔案。可以從兩個方面解決。

修復

方法一:在/usr/local/mysql建立連結檔案

mkdir -p /usr/local/mysql/bin
ln -s /data/wapage/hhzk/mserver/mysql5713/bin/mysqld /usr/local/mysql/bin/mysqld

方法二:將mysqld_safe中的所有/usr/local/mysql目錄改為自己實際的安裝目錄

sed -i 's#/usr/local/mysql#/data/wapage/hhzk/mserver/mysql5713#g'  /data/wapage/hhzk/mserver/mysql5713/bin/mysqld_safe

相關文章