MySQL service provides different connection methods. We generally prefer TCP/IP way where connection is established over Network Socket. There is alternative way named Socket which is connected over local system. During connection we may get error like Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ . In this tutorial we will look to solve this problem.
MySQL服务提供了不同的连接方法。 通常,我们更喜欢通过网络套接字建立连接的TCP / IP方式。 还有另一种名为Socket的方法,它通过本地系统连接。 在连接期间,我们可能会收到类似无法通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器的错误。 在本教程中,我们将寻求解决此问题。
解决方案1 –启动服务 (Solution 1 – Start The Service)
Socket is created by the MySQL service and if the service is not the started the socket will not created. So starting the service is the first step to solve this problem. We will use systemctl
command.
套接字是由MySQL服务创建的,如果服务不是启动的,则不会创建套接字。 因此,启动服务是解决此问题的第一步。 我们将使用systemctl
命令。
$ sudo systemctl start mysql.service
AND check service status
并检查服务状态
$ sudo systemctl status mysql.service
