空白的一坪

从DBA到SRE

导航

Mysql重启报pid文件丢失(持续更新)

mysql重启后报错
信息如下
###################################################
Redirecting to /bin/systemctl start mysql.service
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.
##################################################

查看服务运行信息
systemctl status mysqld.service
##################################################
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
Active: failed (thawing) (Result: exit-code) since Thu 2021-04-08 23:22:55 PDT; 6min ago
Docs: man:systemd-sysv-generator(8)
Process: 13546 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
Process: 33545 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Apr 08 23:22:54 primary systemd[1]: Starting LSB: start and stop MySQL...
Apr 08 23:22:55 primary mysqld[33545]: Starting MySQL. ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).
Apr 08 23:22:55 primary systemd[1]: mysqld.service: Control process exited, code=exited status=1
Apr 08 23:22:55 primary systemd[1]: mysqld.service: Failed with result 'exit-code'.
Apr 08 23:22:55 primary systemd[1]: Failed to start LSB: start and stop MySQL.
##################################################

情形一.异常数据文件影响服务启动
截取错误日志/var/log/mysqld.log
##################################################
2021-04-09T06:38:24.889010Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-04-09T06:38:24.889074Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-04-09T06:38:24.889090Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.23-log) starting as process 35083 ...
mysqld: File '/usr/local/mysql/bin-log/master-bin.index' not found (Errcode: 21 - Is a directory)
2021-04-09T06:38:24.895144Z 0 [ERROR] Aborting

2021-04-09T06:38:24.895151Z 0 [Note] Binlog end
2021-04-09T06:38:24.895251Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
##################################################

日志说未找到/usr/local/mysql/bin-log/master-bin.index文件
迁移或清空对应路径下文件master-bin.index后恢复
mv master-bin.index master-bin.index.bak
再次重启后成功

具体什么原因最好的办法是先查看下错误日志:

1、可能是/usr/local/mysql/data/mysql.pid文件没有写的权限
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data” 然后重新启动mysqld!

2、可能进程里已经存在mysql进程
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9 进程号”杀死,然后重新启动mysqld!

3、可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。
解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。本人就是使用第三条方法解决的 !

4、mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data

5、skip-federated字段问题
解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。

6、错误日志目录不存在
解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限

7、selinux惹的祸,如果是centos系统,默认会开启selinux
解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。

以上摘抄https://blog.csdn.net/miss1181248983/article/details/82426283

情形二.非正常关机导致pid文件丢失
截取错误日志/var/log/mysqld.log
##################################################
2021-04-10T05:58:06.290754Z 0 [ERROR] InnoDB: Table mysql.innodb_table_stats not found.
2021-04-10T05:58:06.290791Z 0 [ERROR] InnoDB: Fetch of persistent statistics requested for table mysql.gtid_executed but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have un
expected structure. Using transient stats instead.
2021-04-10T05:58:06.291796Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2021-04-10T05:58:06.292262Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2021-04-10T05:58:06.292598Z 0 [Note] IPv6 is available.
2021-04-10T05:58:06.292609Z 0 [Note] - '::' resolves to '::';
2021-04-10T05:58:06.292634Z 0 [Note] Server socket created on IP: '::'.
2021-04-10T05:58:06.294492Z 0 [ERROR] Can't start server: can't check PID filepath: No such file or directory
##################################################
1.确认pid文件路径
more /etc/my.cnf |grep -i pid

2.依照my.cnf文件配置,创建对应的文件并修改权限(root特权执行)
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
touch /var/run/mysqld/mysqld.pid
chown mysql:mysql /var/run/mysqld/mysqld.pid
3.再次尝试重启

情形三.如有用户权限启动问题,可尝试如下修改
cp /etc/init.d/mysqld mysqld.bak
修改mysql启动文件/etc/init.d/mysqld中start模块

添加--user=root到mysqld_safe
\(bindir/mysqld_safe --user=root --datadir="\)datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &

尝试重启

posted on 2021-04-09 15:41  行列式  阅读(7249)  评论(0编辑  收藏  举报

后会无期

2011-2-14... ...后来喜欢很浅,喝过酒就忘记,吵完架就放弃