天天看點

service mysqld start 啟動mysql服務報錯:/etc/init.d/mysqld: line 263: @HOSTNAME@: command not found ; /etc/init.d/mysqld: line 276: cd: @prefix@: No such file or directory

問題:

#編譯安裝完成後複制啟動腳本“cp -a mysql.server.sh /etc/init.d/mysqld”後,啟動服務報錯
[root@lfs support-files]# service mysqld start
/etc/init.d/mysqld: line 263: @HOSTNAME@: command not found
/etc/init.d/mysqld: line 276: cd: @prefix@: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (@bindir@/mysqld_safe)           

解決辦法:

#找到/etc/init.d/mysql檔案的263行
263   mysqld_pid_file_path=$datadir/`@HOSTNAME@`.pid      #發現引用了datadir變量;datadir為MySQL Data檔案路徑
#删除`@HOSTNAME@`:
263   mysqld_pid_file_path=$datadir/.pid

#找到變量datadir,發現沒有指派,指派為:
datadir=/usr/local/mysql/data/

#找到276行
276   cd $basedir            #發現引用了basedir變量;basedir為MySQL的安裝路徑
#找到變量basedir,發現同樣沒有指派,指派為
basedir=/usr/local/mysql/           

驗證:

#啟動MySQL
[root@lfs data]# service mysqld start
Starting MySQL SUCCESS! 
#檢視mysql的pid檔案
[root@lfs data]# cat /usr/local/mysql/data/.pid 
18631
#檢視程序
[root@lfs data]# ps -ef |grep 18631
mysql     18631  18366  0 02:06 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data//lfs.err --pid-file=/usr/local/mysql/data//.pid --socket=/tmp/mysql.sock --port=3306           

繼續閱讀