h****n@DESKTOP-*****:~$ sudo mysql [sudo] password for h****n: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
根据报错的信息在 /var/run/mysqld/ 目录下建了一个新的 mysqld.sock 并尝试重启 MySQL 服务后又出现了后面的错误:
1 2 3 4
h****n@DESKTOP-*****:/run/mysqld$ sudo service mysql restart * Stopping MySQL database server mysqld * Starting MySQL database server mysqld su: warning: cannot change directory to /nonexistent: No such file or directory
查了下应该是上次 mysql 服务器异常关机导致的,下面是解决方案:
1 2 3
sudo service mysql stop sudo usermod -d /var/lib/mysql/ mysql sudo service mysql start