问题:
#编译安装完成后复制启动脚本“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