首页 > 代码库 > PID文件丢失处理的方法
PID文件丢失处理的方法
当MySQL实例启动时,会将自己的进程ID写入一个文件中-pid文件,该文件由参数pid_file控制,默认位于数据库目录下,文件名为主机名.pid
mysql> show variables like ‘pid_file‘;
+---------------+--------------------------------+
| Variable_name | Value |
+---------------+--------------------------------+
| pid_file | /opt/mysql/data/gfsunny105.pid |
+---------------+--------------------------------+
1 row in set (0.02 sec)
[root@gfsunny105 data]# cat gfsunny105.pid
4466
1、模拟pid文件丢失
[root@gfsunny105 data]# mv gfsunny105.pid gfsunny105.pid_bak
pid文件丢失对于正在运行着的mysql没有影响,但是在数据库实例重启或者关闭时就会因为没有该文件而报错
2、停止mysql
[root@gfsunny105 data]# service mysqld stop
MySQL server PID file could not be found! [FAILED]
3、找回pid文件
3.1、查看mysql实例进程
[root@gfsunny105 data]# ps -ef|grep mysqld
root 4159 1 0 11:53 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/opt/mysql/data/gfsunny105.pid
mysql 4466 4159 5 11:53 pts/2 00:00:09 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/logs/alert.log --pid-file=/opt/mysql/data/gfsunny105.pid
root 4539 3601 0 11:56 pts/2 00:00:00 grep mysqld
3.2、重新构造pid文件
[root@gfsunny105 data]# ps -ef|grep mysqld|awk ‘{print $2}‘|sed 1d |sed 2d > ${HOSTNAME}.pid
[root@gfsunny105 data]# ll
total 307652
......
-rw-r--r-- 1 root root 5 Jan 19 12:23 gfsunny105.pid
-rw-rw---- 1 mysql mysql 5 Jan 19 11:53 gfsunny105.pid_bak
......
[root@gfsunny105 data]# cat gfsunny105.pid
4466
4、再次停止mysql并重新启动
[root@gfsunny105 data]# service mysqld stop
Shutting down MySQL... [ OK ]
[root@gfsunny105 data]# service mysqld start
Starting MySQL....... [ OK ]
PID文件丢失处理的方法