linux下mysql ERROR 2002 (HY000)错误解决方法

时间:2022-09-19 21:16:54

本人用的的deepin系统 (linux不是windwos哦)
昨天关机的时候报了遗传错误,就预感可能某个程序会出问题,果然,今天来了mysql启动不了了。
用mysql -u root 链接数据库报错

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

到了/var/run/mysqld下查看果然没有mysqld.sock。
于是去/var/log/mysql下看了error.log,日志里发现了这样的错误

[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.

从网上查资料,发现需要删除几个库文件。到/var/lib/mysql下发现有ib_logfile0,ib_logfile1。
果断删除

sudo rm -rf /var/lib/mysql/ib_logfile*

重新启动mysql成功。
发现一个怪问题,我使用

systemctl start mysql.service

没有启动起来。但是使用

/etc/init.d/mysql start

却成功了。
又遇到问题的朋友可以参考我的方法,但是文件路径不一定是这样的,因为安装的时候我是用apt-get安装所以,mysql的文件分布在系统的各个目录下,如果你是自己编译安装,你的ib_logfile文件可能会在mysq’l的目录下。