mac升級XAMPP 7.1.4之後無法啟動MySQL的解決辦法

>> 2017年7月2日 星期日

我的Mac之前裝了XAMPP 5.X,最近因為架設網站需要php 7的測試環境,於是就把原本穩定運作的XAMPP 5.X升級了。
升級的過程都順利,之後也可以正常運作,可是再重新開機之後,卻發現無法啟動MySQL。
(補充說明:這個問題多出現在升級到MariaDB 5.6之後出現)

 在控制介面中看到MySQL Database怎麼按start,只會出現黃燈亮了很久,然後就變回紅燈。

看到這種狀況,下意識感覺不妙。
於是進入終端機(command)模式,想說用指令啟動看看。看到了錯誤訊息。
閱讀錯誤訊息(檔案位置:/Applications/XAMPP/xamppfiles/var/mysql/XXXXXXX-Pro.local.err,XXXXXXX為你的電腦名稱)的最後幾行找到了問題所在。
錯誤訊息如下,如果你發現與我有相同(類似)的訊息,那這篇就是你可以參考的解決方式了:
2017-06-30 20:54:19 140736512222144 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace mysql/gtid_slave_pos uses space ID: 3 at filepath: ./mysql/gtid_slave_pos.ibd. Cannot open tablespace mysql/slave_relay_log_info which uses space ID: 3 at filepath: ./mysql/slave_relay_log_info.ibd
2017-06-30 20:54:19 7fffc5d163c0 InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
InnoDB: Error: could not open single-table tablespace file ./mysql/slave_relay_log_info.ibd
InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.
170630 20:54:19 [ERROR] mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,or misconfigured. This error can also be caused by malfunctioning hardware.
解決方式:
因為全程需要以系統管理員身份處理,所以先切換身份:
# sudo su
接下來,先備份所有的資料庫,需要確定你的資料庫位置,每個人會因安裝XAMPP的位置不同而有所差異。我的位置是在/Applications/XAMPP/xamppfiles/var/mysql/
以下指令為備份資料庫:
# cd /Applications/XAMPP/xamppfiles/var/
# tar -zcvp -f /Users/YOUR_ACCOUNT/Desktop/mysql.tar.gz ./mysql
接下來,在自己的桌面上開一個暫存資料夾:

# mkdir /Users/YOUR_ACCOUNT/Desktop/my_temp 
把mysql中有.ibd的檔案的資料庫裡面的.ibd檔案都移到這個暫存資料夾中。以我的狀況,我發現有ibd的的資料庫有:mysql, phpmyadmin,以下指令就是移動這些檔案
# mkdir /Users/YOUR_ACCOUNT/Desktop/my_temp
# mkdir /Users/YOUR_ACCOUNT/Desktop/my_temp/mysql
# mkdir /Users/YOUR_ACCOUNT/Desktop/my_temp/phpmyadmin
# mv /Applications/XAMPP/xamppfiles/var/mysql/*.ibd /Users/YOUR_ACCOUNT/Desktop/my_temp/mysql
# mv /Applications/XAMPP/xamppfiles/var/phpmyadmin/*.ibd /Users/YOUR_ACCOUNT/Desktop/my_temp/phpmyadmin/

(記得YOUR_ACCOUNT是指你自己在mac下的帳號喔!)


接下來,就回到XAMPP的控制介面,啟動MySQL了。此時應該可以正常啟動了,若是還無法正常啟動,請去查看錯誤訊息,看看在哪的資料庫卡住,然後重複上面步驟,將*.ibd檔案移走,直到可以正常啟動MySQL為止。

看到mysql的紅燈變綠燈先別高興,到此還沒有完全解決。
最後的步驟要完成才算數喔!!!!!!

如果mysql可以正常啟動後,再次把mysql停止。
然後把之前搬走的*.ibd檔案重新搬回去原來的位置。這邊我就不一一列出指令來了,原則上就是前面動作再做一次,只是來源與目標目錄調換。
完成之後再重新啟動MySQL,此時應該都可以正常運作了。

不放心可以在檢查一下錯誤訊息檔案,確定沒有錯誤訊息就大功告成囉!
附註:
在終端機裡啟動MySQL的指令為:

# /Applications/XAMPP/xamppfiles/bin/mysql.server start

參考資料:
https://stackoverflow.com/questions/37856155/mysql-upgrade-failed-innodb-tables-doesnt-exist

補充說明:
檢查/Applications/XAMPP/xamppfiles/var/mysql/裡面有哪些資料夾具有.ibd檔案,可以使用以下指令:

# ls -al /Applications/XAMPP/xamppfiles/var/mysql/*/*.ibd

About This Blog

程式碼標示

  © Free Blogger Templates Joy by Ourblogtemplates.com 2008

Back to TOP