-->
当前位置:首页 > ELSE > 正文内容

记一次Ubuntu宝塔面板mysql恢复过程

Luz4年前 (2020-03-13)ELSE4188

服务器重启后mysql莫名其妙出现错误

root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.  //启动服务失败

root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)  //无法连接sock

root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# lsof -i:3306                                      //查询端口无返回


网上各种修复方法均无效,决定备份数据库文件后重装mysql

root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)    //原始错误
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz    
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# rm -rf  /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz   //删除所有和mysql有关的东西
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# mysql
-bash: /usr/bin/mysql: No such file or directory
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P      //清理残留
sudo: unable to resolve host iZuf6995ou9mbudrzl8w8wZ
dpkg: error: --purge needs at least one package name argument

Type dpkg --help for help about installing and deinstalling packages [*];
Use 'apt' or 'aptitude' for user-friendly package management;
Type dpkg -Dhelp for a list of dpkg debug flag values;
Type dpkg --force-help for a list of forcing options;
Type dpkg-deb --help for help about manipulating *.deb files;

Options marked [*] produce a lot of output - pipe it through 'less' or 'more' !
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# apt autoreclean
E: Invalid operation autoreclean
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# 
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# apt autoreclean
E: Invalid operation autoreclean
root@iZuf6995ou9mbudrzl8w8wZ:/var/lib/dpkg# rm -rf /www/server/mysql   //删除宝塔面板安装的mysql


在宝塔面板重新安装mysql后启动成功

image.png


数据库选项卡中还是原来的项目,但是其实这个位置所有的数据库都已经被删除

导入原来的数据库,在这里可以访问,但是不知道为什么网站依然显示连接数据库失败

在这里将数据库备份成.sql.gz

新建了一个数据库,将.sql.gz恢复进去

修改网站的数据库配置


此时网站访问正常


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。