[mysql] start: Job failed to start invoke-rc.d: initscript mysql, action “start” failed. ,完整移除並重新安裝

剛好同事遇到 mysql 無法正常開啟,但重裝(sudo apt-get install mysql-server-5.6)時卻一直顯示

start: Job failed to start invoke-rc.d: initscript mysql, action “start” failed.

dpkg: error processing mysql-server-5.5 (–configure):

subprocess installed post-installation script returned error exit status 1

或是

Unable to set password for the mysql “root” user…..

嘗試執行 mysql 也會寫著服務的 socket 未開啟

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

 

去看了一下 mysql 的 error.log(var/log/mysql/error.log)

裡面則寫了

InnoDB: Error: unable to create temporary file; errno: 28

Plugin ‘InnoDB’ init function returned error

Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.

看起來可能是 /tmp 目錄的權限有問題

以下指令將 /tmp 資料夾的權限做了正確的調整,完整移除 mysql 的所有資料後,重新安裝就正常了!

(以下指令會將原本的 mysql 資料全部刪除,操作前請先做好備份)

sudo chmod /tmp 777

sudo service mysql stop

sudo killall -KILL mysql mysqld_safe mysqld

sudo apt-get purge mysql-server* mysql-client*

sudo apt-get autoremove --purge

sudo apt-get autoclean

sudo deluser --remove-home mysql

sudo delgroup mysql

sudo rm -rf /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/cache/usr.sbin.mysqld /etc/mysql /var/lib/mysql /var/lib/mysql-files/ /var/log/mysql* /var/log/upstart/mysql.log* /var/run/mysqld

sudo updatedb

sudo apt-get install mysql-server-5.6

Leave a Reply