启动mysqld服务失败,报错如下:
[root@LCM01GCM01 ~]# service mysqld start
Starting mysqld (via systemctl): Jobfor mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" fordetails.
[FAILED]
既然有了提示,先看下有什么帮助没有
[root@LCM01GCM01 ~]# systemctl status mysqld.service
Loaded: loaded (/etc/rc.d/init.d/mysqld)
Active: failed (Result: exit-code) since Wed 2016-01-20 18:26:57CST; 40s ago
Docs:man:systemd-sysv-generator(8)
Process:2979 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
Jan20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....
Jan20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan20 18:26:57 spark01 mysqld[2979]: Starting mysqld: [FAILED]
Jan20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1Jan20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
Jan20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan20 18:26:57 spark01 systemd[1]: mysqld.service failed.
[root@LCM01GCM01 ~]# journalctl -xe--
-- Unit session-2.scope has begun starting up.
Jan20 18:26:48 spark01 sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)
Jan20 18:26:52 spark01 su[2944]: (to root) spark on pts/1Jan20 18:26:52 spark01 su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)
Jan20 18:26:56 spark01 polkitd[909]: Registered Authentication Agent for unix-process:2974:117137 (system bus name :1.25Jan20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....-- Subject: Unit mysqld.service has begun start-up-- Defined-By: systemd-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
--Unit mysqld.service has begun starting up.
Jan20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan20 18:26:57 spark01 mysqld[2979]: Starting mysqld: [FAILED]
Jan20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1Jan20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..--Subject: Unit mysqld.service has failed-- Defined-By: systemd-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
--Unit mysqld.service has failed.--
--The result is failed.
Jan20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan20 18:26:57 spark01 systemd[1]: mysqld.service failed.
Jan20 18:26:57 spark01 polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137 (system bus name :1.
然而,好像这些信息对我们来说并没有什么用处,什么守护进程没启动,我们也不能知如何去启动这些,这个时候我们查看一下mysql自带的告警日志,路径一般在/var/log/mysqld.log下面
[root@LCM01GCM01 ~]# tail -200f /var/log/mysqld.log2018-12-07 T10:00:19.935771Z 0 [ERROR] /usr/sbin/mysqld: Can‘t create/write to file‘/var/run/mysqld/mysqld.pid‘(Errcode: 2 - No such file or directory)
2018-12-07T10:00:19.935795Z 0 [ERROR] Can‘t start server: can‘t create PID file: No such fileor directory181207 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
这个时候我们就明白了,/var/run/mysqld/这个目录不存在,wu,查找下确实没有这个文件。这里我们有两种解决方案
第一种自己创建 /var/run/mysqld/ 这个目录,重新启动mysqld服务
[root@LCM01GCM01 ~]# mkdir -p /var/run/mysqld/[root@LCM01GCM01~]# service mysqld start
Starting mysqld (via systemctl): Jobfor mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" fordetails.
[FAILED]
依旧报错,重新查看告警日志,有以下输出
2018-12-070T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can‘t create/write to file‘/var/run/mysqld/mysqld.pid‘(Errcode: 13 - Permission denied)
2018-12-070T10:28:37.183431Z 0 [ERROR] Can‘t start server: can‘t create PID file: Permission denied181207 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended181207 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
原来,/var/run/mysqld/的属主和属组还是root,mysql并不能在其中创建文件,后修改该目录的属主和属组,启动OK。
[root@LCM01GCM01 ~]# ls -ld /var/run/mysqld/drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/[root@LCM01GCM01~]# chown mysql.mysql /var/run/mysqld/[root@LCM01GCM01~]# service mysqld start
Starting mysqld (via systemctl): [ OK ]
上面第一种解决方案为临时性的方案,你会发现当虚拟机reboot的话,又会启动不成功,那个目录又不删除了,因此我们修改一下存放mysqld.pid的目录,有两个配置文件
vi /etc/my.cnf
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0log-error=/var/log/mysqld.log
pid-file=/createByhujian/mysqld/mysqld.pid
vi /etc/init.d/mysqld
get_mysql_option mysqld datadir"/var/lib/mysql"datadir="$result"get_mysql_option mysqld socket"$datadir/mysql.sock"socketfile="$result"get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"errlogfile="$result"get_mysql_option mysqld_safe pid-file "/createByhujian/mysqld/mysqld.pid"mypidfile="$result"
红色的部分是我自己在根目录下创建的目录 /createByhujian/mysqld
mkdir -p /createByhujian/mysqldchown mysql.mysql /createByhujian/mysqld
重启mysqld服务成功,一劳永逸
有什么问题可以下方留言讨论哦!