今天碰到一个问题,服务器异常关闭,mysql无法启动,查看mysql 状态service mysqld status都提示:MySQL is running but PID file could not be found。
解决方法:
-
使用
ps -elf |grep mysql
查询mysql的进程,了解到pid文件在 /usr/local/var 目录下, 记一下,等会需要这个目录 -
打算先停掉服务,再重启服务
service mysqld stop
提示:MySQL manager or server PID file could not be found!
解决: 使用 ps -elf |grep mysql |grep -v grep
将查询出来的和mysql 相关的进程全部kill 掉,再重启,使用命令:
service mysqld start
- 然而还是不行,一直停留在
查看状态
于是去把lock 先删掉
[[email protected] ~]# cd /var/lock/subsys/
[[email protected] subsys]# ls
crond local mysql network nscd ntpd rsyslog sshd
[[email protected] subsys]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[[email protected] subsys]# rm -rf ./mysql
[[email protected]u9kjuZ subsys]# ls
crond local network nscd ntpd rsyslog sshd
查看mysql 状态service mysqld status都提示:MySQL is running but PID file could not be found
这个时候去把 mysql 中 data 目录下的 mysql-bin.index 文件找到,然后删除
[[email protected] subsys]# find / -name mysql-bin.index
/usr/local/var/mysql-bin.index
[[email protected] subsys]# rm -rf /usr/local/var/mysql-bin.index
然后找到 并 kill 所有关于 mysql 或者 mysqld 的进程
ps -aux | grep mysql
- 到这一般来说基本可以了,但是启动mysql服务时候还是出现
MySQL is running but PID file could not be found
这时候就要另辟蹊径 了。
刚第一步的时候说到,pid 文件所在的目录,打开这个目录,我们看到确实没有找到 xxxxx.pid 文件,但是有一个 xxxx.err文件,于是打开看一下,都有哪些运行错误记录,然后找到了最关键的一条:
181121 10:48:28 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
/usr/local/libexec/mysqld: Disk is full writing './mysql-bin.~rec~' (Errcode: 28). Waiting for someone to free space... (Expect up to 60 secs delay for server to continue after freeing disk space)
/usr/local/libexec/mysqld: Retry in 60 secs. Message reprinted in 600 secs
/usr/local/libexec/mysqld: Retry in 60 secs. Message reprinted in 600 secs
/usr/local/libexec/mysqld: Retry in 60 secs. Message reprinted in 600 secs
/usr/local/libexec/mysqld: Retry in 60 secs. Message reprinted in 600 secs
181121 11:00:31 mysqld_safe mysqld from pid file /usr/local/var/iZ253su9kjuZ.pid ended
那就是 Disk is full writing './mysql-bin.~rec~' (Errcode: 28). Waiting for someone to free space...
我进mysql数据目录查看,发现有很多以前的二进制日志,所以打算清空2017年前所有的二进制日志。
解决办法:
先rm删除binlog日志,再purge binary logs to '具体的binlog’删除。
注意:purge binary logs to 'mysql-bin.00003’表示清理mysql-bin.00003之前的所有binlog,但不包括mysql-bin.00003本身。
注意:如果只rm,不purge,重启mysql的话,会报错的,mysql就起不来了。所以rm删除后,需要及时执行purge命令。
[[email protected] var]# purge binary logs to 'mysql-bin.00034'
于是就OK了,mysql服务终于重新启动了,数据也没有丢失
[[email protected] var]# service mysqld status
MySQL is not running [ʧ▒▒]
[[email protected] var]# service mysqld start
Starting MySQL. [ȷ▒▒]
[[email protected] var]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.51-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql
Database changed
补充一个mysql修改用户密码的命令