ERROR 2002 (HY000): 无法通过 socket '/var/lib/mysql/mysql.sock' 连接到本地 MySQL 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26163704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
提问by Ukuser32
I have installed Centos7 update, removed MariaDB and done a fresh install of MySQL - additionally I have removed it and reinstalled it but everytime I connect to mysql -u root -p I get the titled error. Additionally I havelooked at other tickets associated with this but still not making progress. If I run service mysqld restart it says "Redirecting to /bin/systemctl restart mysqld.service" and then just hangs. Really not a linux expert so not sure what is causing this?
我已经安装了 Centos7 更新,删除了 MariaDB 并重新安装了 MySQL - 另外我已经删除并重新安装了它,但是每次我连接到 mysql -u root -p 时我都会收到标题错误。此外,我也看了一下与此相关的其他门票,但仍然没有取得进展。如果我运行 service mysqld restart 它说“重定向到 /bin/systemctl restart mysqld.service”然后就挂了。真的不是 linux 专家,所以不确定是什么原因造成的?
回答by John L
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:
我遇到了同样的问题,并在挖掘后发现了一些事情。MariaDB 是 mysql 的替代品。在新系统上,mysql 是 MariaDB 客户端(虽然我不清楚这意味着什么)。我检查了服务是否正在运行:
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)
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.
换句话说,mysqld 服务没有运行。
启动服务对我有用:`systemctl start mariadb.service`
Now all the mysql commands work as expected.
现在所有 mysql 命令都按预期工作。
要打结,请在启动时启用该服务:`systemctl enable mariadb.service`
回答by J Jorgenson
Check the 'socket=' entry in your /etc/my.cnf within the [mysqld]section:
检查[mysqld]部分中/etc/my.cnf 中的“socket=”条目:
[mysqld1]
socket = /tmp/mysql.sock1
An alternate method is to provide the '-hhost' & '-Pport' parameters to the 'mysqladmin' or 'mysql' commands, to avoid using the socket.
另一种方法是向“mysqladmin”或“mysql”命令提供“-hhost”和“-Pport”参数,以避免使用套接字。
mysql -u user -hservername -P3006 -p -Dschema
mysqladmin -u user -p -hhostname -Pport
回答by Ukuser32
Removing the dir fixed it - deleted the dir (with rm -rf "dir name") and then unintalled mysql "yum remove mysql mysql-server" then reinstalled "yum install mysql-server" and ran "service mysqld start"
删除目录修复它 - 删除目录(使用 rm -rf "dir name")然后卸载 mysql "yum remove mysql mysql-server" 然后重新安装 "yum install mysql-server" 并运行 "service mysqld start"
If you have this problem with the start mysql service hanging - check the logs /var/log/mysqld.log as suggested by Jeremiah.
如果您在启动 mysql 服务挂起时遇到此问题 - 按照 Jeremiah 的建议检查日志 /var/log/mysqld.log。