Linux VPS 尝试连接 MySQL 服务时出现错误 2002

Linux VPS 尝试连接 MySQL 服务时出现错误 2002

我正在尝试在运行 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

答案1

问题说mysql应该默认安装在 Kali 上。除非你故意删除它,否则你到底想做什么?

您正在使用不同的方法来管理 mysql:(1)显然没有名为“mysql.service”的服务,因此您无法启动它。 (2)然后您尝试停止使用sudo mysql stop,显然如果一开始就没有启动,您就无法停止它。

做什么sudo mysql start

相关内容