首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> MySQL 資料庫 >> MySQL 綜合教學

Ubuntu 下 MySQL 設置開機自啟動故障排查:chkconfig vs update-rc.d

     編輯:MySQL 綜合教學

Ubuntu 下 MySQL 設置開機自啟動故障排查:chkconfig vs update-rc.d

在 Ubuntu 嘗試用 chkconfig 管理 MySQL 自啟動遇到連串報錯,最終發現 Ubuntu 屬於 Debian 系,應使用 update-rc.d 而非 chkconfig。

錯誤復現


# chkconfig --list
The program 'chkconfig' is currently not installed.
# apt-get install chkconfig
# chkconfig --list | grep mysql
mysql 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# chkconfig mysql on
/sbin/insserv: No such file or directory
# ln -s /usr/lib/insserv/insserv /sbin/insserv
# chkconfig mysql on
The script you are attempting to invoke has been converted to an Upstart job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'mysql' missing LSB tags and overrides
...

根因分析

  • chkconfig 是 RedHat/Fedora 系工具,依賴 SysV init 腳本與 LSB 標籤。
  • Ubuntu 早期已遷移至 Upstart(後遷 systemd),MySQL 安裝包提供的是 Upstart Job 配置(/etc/init/mysql.conf),非標準 SysV 腳本,chkconfig/insserv 無法識別。
  • 強行建立 /sbin/insserv 軟鏈接只會引發更多錯誤。

正確解決方案


# 刪除誤建的軟鏈接
rm -f /sbin/insserv

# 使用 Debian/Ubuntu 原生工具
sudo update-rc.d mysql defaults

驗證


# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Runlevel 2-5 顯示 on 即表示開機自啟動已生效。

補充說明

  • Ubuntu 16.04+ 使用 systemd,推薦 systemctl enable mysql。
  • 若必須用 chkconfig,需安裝 sysv-rc-conf 或手動管理 /etc/rc*.d/ 軟鏈接,不推薦。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved