最近發(fā)現(xiàn)mysql56已停止,即使已經(jīng)安裝并配置好了,也無(wú)法啟動(dòng)。經(jīng)過(guò)查找和嘗試,發(fā)現(xiàn)原因是數(shù)據(jù)文件損壞或者權(quán)限問(wèn)題。
$ sudo systemctl status mysql # 輸出如下信息: # mysql.service - MySQL Community Server # Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) # Active: inactive (dead) $ sudo systemctl start mysql # 啟動(dòng)失敗,輸出如下信息: # Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details. $ sudo journalctl -xe # 輸出如下錯(cuò)誤信息: # Sep 10 10:34:58 ubuntu16 mysqld[15365]: 2019-09-10T02:34:58.717887Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
以上錯(cuò)誤信息表明是因?yàn)閿?shù)據(jù)文件無(wú)法鎖定,導(dǎo)致無(wú)法啟動(dòng)。解決方法如下:
$ sudo chown -R mysql:mysql /var/lib/mysql # 修改mysql的數(shù)據(jù)目錄所屬用戶(hù)為mysql $ sudo chmod -R 755 /var/lib/mysql # 給數(shù)據(jù)目錄權(quán)限775,保證mysql用戶(hù)可以訪(fǎng)問(wèn) $ sudo systemctl start mysql # 再次啟動(dòng)mysql,即可成功 $ sudo systemctl status mysql # 輸出結(jié)果如下信息: # mysql.service - MySQL Community Server # Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) # Active: active (running) since Tue 2019-09-10 10:43:53 CST; 3min 43s ago
通過(guò)以上操作,成功解決了mysql56無(wú)法啟動(dòng)的問(wèn)題。需要注意的是,因?yàn)閙ysql的數(shù)據(jù)目錄所在的權(quán)限問(wèn)題導(dǎo)致無(wú)法啟動(dòng)的原因還有其他的可能性,需要根據(jù)具體的錯(cuò)誤信息進(jìn)行排查和解決。