总是报错:
1、Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.2、ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
3、error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
解决方法:(下面几个操作我也不知道是哪个起作用的,都做一遍吧)
1、重启mysql
sudo systemctl stop mysql
sudo systemctl start mysql
2、使用安全模式进入mysql(就是免密登陆)
sudo mysqld_safe --skip-grant-tables
3、修改localhost和端口号
来源:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
修改这个文件中的ip和端口号,如何没有这个文件夹,新建一个,然后重启mysql
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
ps:网上还有一个方法是在这个文件最后加上下面这个,但是我跑不起来,会报错
--skip-grant-tables
4、 查看当前用户组的帐号密码(这个肯定有用)
sudo cat /etc/mysql/debian.cnf
然后用这个账户和密码登陆
sudo mysql -u debian-sys-maint -p
如图:
5、重装mysql!!!!
如果前面的操作都没有用的话,建议直接重装
先看一下相关的包都有哪些
sudo dpkg -l | grep mysql
然后使用apt purge命令卸载mysql(purge会删除配置文件,remove不会)
sudo apt purge mysql-server mysql-client mysql-server-8.0 mysql-client-8.0 mysql-common
安装:
sudo apt install mysql-server mysql-client