第一步:
把開機啟動腳本(mysqld)copy到文件夾/etc/init.d 或 /etc/rc.d/init.d 中,
第二步:有兩種方法
方法1:
將啟動程序的命令添加到 /etc/rc.d/rc.local 文件中,比如:
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/etc/init.d/mysqld start #就是添加這一條語句
注:
/etc/init.d 是 /etc/rc.d/init.d 的軟鏈接
/etc/rc.local 是 /etc/rc.d/rc.local 的軟鏈接
方法2:
使用命令chkconfig設置開機啟動
chkconfig功能說明:檢查,設置系統的各種服務 語法: chkconfig [--add][--del][--list][系統服務] 或 chkconfig [--level<等級代號>][系統服務][on/off/reset] --add 添加服務 --del 刪除服務 --list 查看各服務啟動狀態
比如設置自啟動mysql:
#將mysql啟動腳本放入所有腳本運行目錄/etc/rc.d/init.d中 cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld #改變權限 chown root.root /etc/rc.d/init.d/mysqld #所有用戶都可以執行,單只有root可以修改 chmod 755 /etc/rc.d/init.d/mysqld #將mysqld 放入linux啟動管理體系中 chkconfig --add mysqld #查看全部服務在各運行級狀態 chkconfig --list mysqld #只要運行級別3啟動,其他都關閉 chkconfig --levels 245 mysqld off
————————————————
原文鏈接:https://blog.csdn.net/qq_26182553/java/article/details/80414950