Linux

Linux VPS 嘗試連接 MySQL 服務時出現 ERROR 2002

  • March 19, 2019

我正在嘗試在執行 Kali (Debian) 的 VPS 上設置 SQL 當我執行任何命令時,我收到以下錯誤:

root@kali:~# sudo service mysql restart
Failed to restart mysql.service: Unit mysql.service not found.

root@kali:~# sudo mysql stop
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

我已經嘗試重新啟動系統,但我得到了同樣的錯誤。我嘗試重新安裝 MySQL,但出現此錯誤:

root@kali:~# sudo apt-get install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package mysql-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'mysql-server' has no installation candidate

我試圖用我的節點密碼和空白密碼登錄 MySQL(因為這是第一次訪問),但我遇到了同樣的錯誤 2002:

root@kali:~# sudo mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

我在自己的網路上執行 VPS,該網路是埠轉發的,並且是執行 Kali 的 R-Pi 3。

更新:如果我在我的目錄中列出目錄,/var/run我會看到:

root@kali:~# cd /var/run
root@kali:/var/run# ls
NetworkManager     lightdm             openvpn-client   sshd.pid
agetty.reload      lightdm.pid         openvpn-server   sudo
console-setup      lock                pcscd            systemd
crond.pid          log                 postgresql       tmpfiles.d
crond.reboot       mlocate.daily.lock  samba            udev
dbus               motd.dynamic        screen           user
dhclient-eth0.pid  mount               sendsigs.omit.d  utmp
dhclient.eth0.pid  network             shm
initctl            openvpn             sshd

這個問題說mysql應該預設安裝在 Kali 上。除非您故意將其刪除,否則您到底想完成什麼?

您正在使用不同的方法來管理 mysql: (1) 顯然沒有名為“mysql.service”的服務,因此您無法啟動它。(2)然後您嘗試停止使用sudo mysql stop,如果一開始沒有開始,顯然您無法停止它。

做什麼sudo mysql start

引用自:https://serverfault.com/questions/958407