ERROR 2002(HY000):无法通过socket' /var/lib/mysql/mysql.sock&#39连接到本地MySQL服务器;

时间:2014-10-02 15:00:54

标签: mysql centos7

我已经安装了Centos7更新,删除了MariaDB并完成了全新的MySQL安装 - 另外我已将其删除并重新安装它但每次我连接到mysql -u root -p时都会收到标题错误。此外,我已经查看了与此相关但尚未取得进展的其他门票。如果我运行服务mysqld restart它会显示“重定向到/ bin / systemctl重启mysqld.service”,然后挂起。真的不是Linux专家,所以不确定是什么导致这个?

4 个答案:

答案 0 :(得分:10)

I had the same problem and found out a few things after digging around. MariaDB is a drop-in replacement for mysql. On the new system, mysql is the MariaDB client (although I'm not clear on what that means). I checked to see if the service was running:

service mysqld status

which indicated:

Redirecting to /bin/systemctl status mysqld.service mysqld.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)

In other words, the mysqld service is not running.

Starting the service worked for me:
`systemctl start mariadb.service`

Now all the mysql commands work as expected.

To tie the last knot, enable the service at boot:
`systemctl enable mariadb.service`

答案 1 :(得分:0)

检查' socket ='在 [mysqld] 部分的/etc/my.cnf中输入:

[mysqld1]
socket = /tmp/mysql.sock1

另一种方法是提供' -hhost' &安培; ' -Pport' ' mysqladmin'的参数或者' mysql'命令,以避免使用套接字。

mysql -u user -hservername -P3006 -p   -Dschema
mysqladmin -u user -p -hhostname -Pport 

答案 2 :(得分:0)

删除dir修复它 - 删除了dir(用rm -rf“dir name”)然后unintalled mysql“yum remove mysql mysql-server”然后重新安装“yum install mysql-server”并运行“service mysqld start”

如果启动mysql服务时遇到此问题 - 请按照Jeremiah的建议检查日志/var/log/mysqld.log。

答案 3 :(得分:0)

如果您查看 MariaDB 日志文件,您可能会发现该问题与创建 pid 文件有关。解决方法:创建PID目录,然后将其所有者更改为mysql:mysql