问题描述:启动mysql时报错"/etc/init.d/mysqld: Permission denied",如下所示:
数据库:mysql 5.5.18
系统:rhel 6.5
1、异常重现
[root@MySQL5518-Master ~]# service mysqld start
env: /etc/init.d/mysqld: Permission denied

2、解决步骤
[root@MySQL5518-Master ~]# ll /etc/init.d/mysqld
-rw-r--r--. 1 root root 10725 Aug 15 00:17 /etc/init.d/mysqld
[root@MySQL5518-Master ~]# chmod +x /etc/init.d/mysqld

说明:给/etc/init.d/mysqld添加执行权限即可.

[root@MySQL5518-Master ~]# service mysqld start
/etc/init.d/mysqld: line 256: my_print_defaults: command not found
/etc/init.d/mysqld: line 276: cd: /usr/local/mysql: No such file or directory
Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[FAILED]ld_safe)

说明:如上所示,新出现两个问题.
问题一:/usr/local/mysql: No such file or directory
处理过程:
[root@MySQL5518-Master ~]# mkdir -p /usr/local/mysql
[root@MySQL5518-Master ~]# cd /usr/local
[root@MySQL5518-Master local]# chown -R mysql:mysql mysql

问题二:my_print_defaults: command not found
处理过程:
a、修改/etc/init.d/mysqld
[root@MySQL5518-Master ~]# vi /etc/init.d/mysqld
#按以下变量内容修改 
basedir=/usr/local/mysql 
将其修改为
basedir=/usr/local/webserver/mysql

b、修改/etc/my.cnf文件
[root@MySQL5518-Master local]# vi /etc/my.cnf
#按以下变量内容修改 
basedir=/usr/local/mysql 
将其修改为
basedir=/usr/local/webserver/mysql

原因:在执行mysql_install_db命令时使用的basedir为/usr/local/webserver/mysql.
[root@MySQL5518-Master mysql-5.5.18]# /usr/local/webserver/mysql/scripts/mysql_install_db \
--user=mysql \
--basedir=/usr/local/webserver/mysql \
--datadir=/var/mysql/data

3、结果验证
[root@MySQL5518-Master local]# service mysqld start
Starting MySQL..                                           [  OK  ]

[root@MySQL5518-Master local]# ps -ef|grep mysql
root       4363      1  0 10:28 pts/1    00:00:00 /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --datadir=/var/mysql/data --pid-file=/var/mysql/data/MySQL5518-Master.pid
mysql      4782   4363  0 10:28 pts/1    00:00:00 /usr/local/webserver/mysql/bin/mysqld --basedir=/usr/local/webserver/mysql --datadir=/var/mysql/data --plugin-dir=/usr/local/webserver/mysql/lib/plugin --user=mysql --log-error=/var/mysql/data/MySQL5518-Master.err --pid-file=/var/mysql/data/MySQL5518-Master.pid --socket=/tmp/mysql.sock --port=3306
root       4807   2488  0 10:28 pts/1    00:00:00 grep mysql

说明:此后成功开启mysql.