无法通过套接字'/var/lib/mysql/mysql.sock'连接到本地MySQL服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8936737/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:25:14  来源:igfitidea点击:

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

mysqlconnection

提问by MUFC

I tried restarting the Mysql server but its not working for me. I am sure the server is running and the permissions on the folder /var/lib/mysql/are correct (777).

我尝试重新启动 Mysql 服务器,但它对我不起作用。我确信服务器正在运行并且文件夹的权限/var/lib/mysql/是正确的 (777)。

When i tried to open the file mysql.sock, its giving me an error saying the file may be corrupt.

当我试图打开文件 mysql.sock 时,它给我一个错误,说文件可能已损坏。

Please help me log in to DB. Thanks in advance.

请帮我登录数据库。提前致谢。

This is how My.cnf looks

这是 My.cnf 的样子

datadir=/var/lib/mysq
socket=/var/lib/mysql/mysql.sock
user=mysql
#Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
skip-external-locking

采纳答案by Mahesh Patil

you can check if mysql is running with the following command: mysqladmin -u root -p status

您可以使用以下命令检查 mysql 是否正在运行:mysqladmin -u root -p status

Also try changing your permission to mysql folder. If you are working locally, you can try:

还可以尝试更改您对 mysql 文件夹的权限。如果您在本地工作,您可以尝试:

sudo chmod -R 777 /var/lib/mysql/

须藤 chmod -R 777 /var/lib/mysql/

回答by Ralph

mysqld has to be started in order of the mysql.sock to be created and access by any process. check whether it is running.

mysqld 必须按照 mysql.sock 被任何进程创建和访问的顺序启动。检查它是否正在运行。

I had same issue and checked whether the mysqld was running and I found out that is wasn't, so I started mysqld. That should resolve the problem.

我遇到了同样的问题并检查了 mysqld 是否正在运行,但我发现它没有运行,所以我启动了 mysqld。那应该可以解决问题。

回答by Abdul Manaf

As what you have give from your my.cnf .

正如您从 my.cnf 中获得的一样。

Please make sure that both socket points to same file.You are missing it.Please make it sure. Change it as i have changed

请确保两个套接字都指向同一个文件。您丢失了它。请确定。像我一样改变它

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/lib/mysql/mysql.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
skip-external-locking

your both sockets are pointing to different files.

您的两个套接字都指向不同的文件。

Try it..

尝试一下..

回答by CristianDonosoC

I had the same problem a while ago. I updated my machine and the socket ceased to work. My solution was to change the socket to a location where it could be opened by every process.

不久前我遇到了同样的问题。我更新了我的机器,插座停止工作。我的解决方案是将套接字更改为每个进程都可以打开的位置。

In /etc/mysql/my.cnf (or where this file is)

在 /etc/mysql/my.cnf (或此文件所在的位置)

    [client]
    port = 3306
    #socket = /var/run/mysqld/mysqld.sock
    socket = /tmp/mysqld.sock # This location did it for me


    [mysqld_safe]
    #socket = /var/run/mysqld/mysqld.sock
    socket = /tmp/mysqld.sock 
    ...

    [mysqld]
    ...
    #socket = /var/run/mysqld/mysqld.sock
    socket = /tmp/mysqld.sock
    ...

It seems important that all the profiles use the same socket. Also you would want to change the /etc/mysql/debian.cnf and update the socket. Hope this helps!

所有配置文件都使用相同的套接字似乎很重要。您还需要更改 /etc/mysql/debian.cnf 并更新套接字。希望这可以帮助!

回答by Krishna Oza

Unless the mysqld service is running the mysql.sock file is not present in the directory /var/lib/mysql; Please start the mysqld using service mysqld start as root user;

除非 mysqld 服务正在运行,否则目录 /var/lib/mysql 中不存在 mysql.sock 文件;请以 root 用户身份使用 service mysqld start 启动 mysqld;

and then run mysql from shell to start the mysql database; This worked for me with same error message;

然后从shell运行mysql来启动mysql数据库;这对我有用,但有相同的错误消息;

回答by Brom558

You may want to check the permissions, owner and group on files for the /var/lib/mysqldirectory, as well as the files within it.

您可能想要检查/var/lib/mysql目录的文件的权限、所有者和组,以及其中的文件。

I had a similar issue causes when i moved the /var/lib/mysqldirectory to a new machine. During the copy the permissions were changed, and the owner and group were changed to root. Changing the owner and group (chown user:group file/directory) and permissions (chmod <value> filename/s) to the MySQL admin account resolved the issue.

当我将/var/lib/mysql目录移动到新机器时,我遇到了类似的问题。在复制期间,权限已更改,所有者和组已更改为 root。将所有者和组 ( chown user:group file/directory) 以及权限 ( chmod <value> filename/s) 更改为 MySQL 管理员帐户解决了该问题。