找不到 mysql.sock

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

Cannot find mysql.sock

mysqlmacossocketsinstall

提问by Tony

I just had to re-install mysql and I am having a problem starting it up. It cannot find the socket (mysql.sock). The problem is that neither can I. In my Mac OS X 10.4 terminal, I type: locate mysql.sock, and I get back /private/tmp/mysql.sock. It makes sense that the socket file exist in that location, but it actually does not.

我只需要重新安装 mysql,但在启动时遇到了问题。它找不到套接字(mysql.sock)。问题是我也不能。在我的 Mac OS X 10.4 终端中,我输入:locate mysql.sock,然后返回/private/tmp/mysql.sock。套接字文件存在于该位置是有道理的,但实际上并不存在。

  1. How can I find the socket file?

  2. If locate is returning a false location, it must have some sort of memory and probably indexes. How can I refresh that index?

  1. 如何找到套接字文件?

  2. 如果 locate 返回一个错误的位置,它必须有某种内存和可能的索引。如何刷新该索引?

回答by behas

to answer the first part of your question:

回答你问题的第一部分:

run

% mysqladmin -p -u <user-name> variables

and check the 'socket' variable

并检查“socket”变量

回答by Eugene Ramirez

This solved my problem

这解决了我的问题

mysql_config --socket

UPDATE

更新

mysql_config can tell us where the file mysql.sock should be, but in my case the file didn't exist. So, I've deleted my.cnf:

mysql_config 可以告诉我们文件 mysql.sock 应该在哪里,但在我的情况下该文件不存在。所以,我已经删除了 my.cnf:

sudo rm -rf /etc/my.cnf

And then restarted mysql:

然后重启mysql:

brew services restart mysql

The file was created and mysql is now running well.

该文件已创建,mysql 现在运行良好。

回答by Alnitak

The socket file should be created automatically when the MySQL daemon starts.

套接字文件应在 MySQL 守护程序启动时自动创建。

If it isn't found, most likely the directory which is supposed to contain it doesn't exist, or some other file system problem is preventing the socket from being created.

如果没有找到,很可能应该包含它的目录不存在,或者其他一些文件系统问题阻止了套接字的创建。

To find out where the file should be, use:

要找出文件应该在哪里,请使用:

% mysqld --verbose --help | grep ^socket

回答by zero_cool

This found it for me:

这为我找到了:

netstat -ln | grep mysql

Mac OSX

Mac OSX

回答by Matthias D.

My problem was also the mysql.sock-file.

我的问题也是 mysql.sock 文件。

During the drupal installation process, i had to say which database i want to use but my database wasn't found

在drupal安装过程中,我不得不说我想使用哪个数据库但我的数据库没有找到

mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock

the system is searching mysql.sock but it's in the wrong directory

系统正在搜索 mysql.sock 但它在错误的目录中

all you have to do is to link it ;)

你所要做的就是链接它;)

it took me a lot of time to google all important informations but it took me even hours to find out how to adapt , but now i can present the result :D

我花了很多时间在谷歌上搜索所有重要信息,但我什至花了几个小时来找出如何适应,但现在我可以展示结果:D

ps: if you want to be exactly you have to link your /tmp/mysql.sock-file(if it is located in your system there too) to the directory given by the php.ini (or php.default.ini) where pdo_mysql.default_socket= ...

ps:如果你想完全正确,你必须将你的/tmp/mysql.sock-file(如果它也位于你的系统中)链接到由 php.ini(或 php.default.ini)给出的目录,其中pdo_mysql.default_socket= ...

回答by mattbell87

I got the exact path using:

我使用以下方法获得了确切路径:

netstat -ln | grep -o -m 1 -E '\S*mysqld?\.sock'

Since this only returns the path and doesn't require any input you could potentially use it in a shell script.

由于这仅返回路径并且不需要任何输入,因此您可以在 shell 脚本中使用它。

MySQL must be currently running on your machine for this to work. Works for MariaDB too.

MySQL当前必须在您的机器上运行才能正常工作。也适用于 MariaDB。

回答by Amy D

The original questions seems to come from confusion about a) where is the file, and b) where is it being looked for (and why can't we find it there when we do a locate or grep). I think Alnitak's point was that you want to find where it was linked to - but grep will not show you a link, right? The file doesn't live there, since it's a link it is just a pointer. You still need to know where to put the link.

最初的问题似乎来自关于 a) 文件在哪里的混淆,以及 b) 在哪里寻找它(以及为什么我们在执行 locate 或 grep 时找不到它)。我认为 Alnitak 的观点是您想找到它链接到的位置 - 但 grep 不会向您显示链接,对吗?该文件不在那里,因为它是一个链接,它只是一个指针。您仍然需要知道将链接放在哪里。

my sock file is definitely in /tmp and the ERROR I am getting is looking for it in /var/lib/ (not just /var) I have linked to /var and /var/lib now, and I still am getting the error "Cannot connect to local MySQL server through socket 'var/lib/mysql.sock' (2)".

我的 sock 文件肯定在 /tmp 中,我得到的错误是在 /var/lib/(不仅仅是 /var)中寻找它,我现在已经链接到 /var 和 /var/lib,但我仍然收到错误“无法通过套接字‘var/lib/mysql.sock’(2)连接到本地 MySQL 服务器”。

Note the (2) after the error.... I found on another thread that this means the socket might be indeed attempted to be used, but something is wrong with the socket itself - so to shut down the machine - completely - so that the socket closes. Then a restart should fix it. I tried this, but it didn't work for me (now I question if I restarted too quickly? really?) Maybe it will be a solution for someone else.

注意错误后的 (2) .... 我在另一个线程上发现这意味着可能确实尝试使用套接字,但套接字本身有问题 - 所以要关闭机器 - 完全 - 这样插座关闭。然后重新启动应该修复它。我试过这个,但它对我不起作用(现在我怀疑我是否重新启动太快了?真的?)也许它会成为其他人的解决方案。

回答by soarinblue

$ mysqladmin variables | grep sock

Try this instead, this will output the demanded result, getting rid of unrelated info.

试试这个,这将输出所需的结果,摆脱不相关的信息。

回答by Timbinous

To refresh the locate's database I ran

为了刷新我运行的定位数据库

/usr/libexec/locate.updatedb

回答by Padhraic

(Q1) How can I find the socket file?

(Q1) 如何找到socket文件?

The default location for the socket file is /tmp/mysql.sock, to find the socket file for your system use this.

套接字文件的默认位置是/tmp/mysql.sock,要查找系统的套接字文件,请使用它。

mysqladmin variables | grep socket

If you have just installed MySql the mysql.sock file will not be created until the server is started. Use this command to start it.

如果您刚刚安装了 MySql,则在服务器启动之前不会创建 mysql.sock 文件。使用此命令启动它。

sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

If prompted for a password you can pass the username root or other username like this. Terminal will prompt you for the password.

如果提示输入密码,您可以像这样传递用户名 root 或其他用户名。终端将提示您输入密码。

mysqladmin --user root --password variables | grep socket

(Q2) How can I refresh locate index

(Q2) 如何刷新定位索引

Refresh the locate db with this command.

使用此命令刷新 locate db。

sudo /usr/libexec/locate.updatedb