SQLSTATE[HY000][2002]没有这样的文件或目录[复制]

时间:2022-10-14 14:09:04

This question already has an answer here:

这个问题已经有了答案:

I am trying to run a laravel project on OS X. I installed MySql with homebrew. I tried googling around for why I'm getting this error:

我想在OS x上运行一个laravel项目,我用homebrew安装了MySql。我试着在网上搜索为什么会有这样的错误:

SQLSTATE[HY000] [2002] No such file or directory

when I try to do

当我试着去做的时候

php artisan migrate

And most of the answers I see say php and MySql cannot communicate to each other. I've been trying to see where I went wrong since I think I followed previous posts about it, and it still doesn't work. I created a page that just does this:

我看到的大多数答案是php和MySql不能相互通信。我一直试着去看我哪里出了问题,因为我觉得我之前的帖子都是这样写的,但它还是不起作用。我创建了这样一个页面:

<?php
    phpinfo();
?>

And I see these types of things: In the Configure area, I see:

我看到了这些类型的东西:在配置区域,我看到:

'--with-mysql-sock=/tmp/mysql.sock' '--with-mysqli=mysqlnd' '--with-mysql=mysqlnd' '--with-pdo-mysql=mysqlnd' '--enable-pcntl' '--enable-zend-signals' '--enable-dtrace'

loaded configuration file:

加载配置文件:

/usr/local/etc/php/5.4/php.ini

If I ls /tmp, I do see mysql.sock.

如果我是ls /tmp,我会看到sqmyl .sock。

In that php.ini file, I set these lines: pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket = /tmp/mysql.sock mysqli.default_socket = /tmp/mysql.sock

php。ini文件,我设置了这些行:pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket=/tmp/mysql。袜子mysqli.default_socket = / tmp / mysql.sock

And then in /usr/local/Cellar/mysql/5.6.16/my.cnf, I added the following line:

然后在/usr/local/Cellar/mysql/5.6.16/my.cnf中,我添加了以下一行:

socket = /tmp/mysql.sock

I DID restart apache, as well as check mysql is running. I haven't seen any other advice besides the php and mysql connection. I think there are two versions of php on my system because when I installed mcrypt or something else I can't remember, it installed another php version. But when I do look at the output of phpinfo, I'm editing the appropriate php.ini file. I didn't know if there is another piece I am missing. Any thoughts? Thanks

我重新启动了apache,并检查mysql是否运行。除了php和mysql连接之外,我没有看到任何其他建议。我认为我的系统上有两个php版本,因为当我安装mcrypt或其他我不记得的东西时,它安装了另一个php版本。但是当我查看phpinfo的输出时,我正在编辑适当的php。ini文件。我不知道我是否还漏掉了另一件东西。任何想法吗?谢谢

7 个解决方案

#1


43  

I had a similar error. I am using MAMP and what solved my issue was:

我也有类似的错误。我正在使用MAMP,解决我的问题的是:

  1. creating a symbolic link in: /var/mysql (create the directory if it does not exist)
  2. 在:/var/mysql中创建一个符号链接(如果目录不存在就创建它)
  3. cd /var/mysql && sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock
  4. cd /var/mysql & sudo ln -s / application /MAMP/tmp/mysql/mysql.sock

#2


7  

For users which are looking for a solution on XAMPP (Tested and worked on Mac OS X),

对于正在寻找XAMPP解决方案的用户(在Mac OS X上测试和工作),

Open terminal and create a symbolic link :

打开终端,创建一个符号链接:

sudo mkdir /var/mysql
cd /var/mysql
sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

Others solutions explained here : http://pravams.com/2011/05/26/magento-pdo-exception/

其他解决方案如下:http://pravams.com/2011/05/26/magento-pdo-exception/

#3


6  

After searching, I found this post:

搜索之后,我找到了这个帖子:

Setting up Laravel on a Mac php artisan migrate error: No such file or directory

在Mac php artisan上设置Laravel迁移错误:没有这样的文件或目录

Once I added

一旦我添加

'unix_socket' => '/tmp/mysql.sock’,

to my database.php in the mysql array, it worked. Not sure exactly why that works, but it does.

我的数据库。在mysql数组中,它起作用了。不知道为什么会这样,但确实如此。

#4


5  

I found PHP on CentOS 6 built with mysql.default_socket=/var/lib/mysql/mysql.sock yet for some reason pdo_mysql.default_socket=/tmp/mysql.sock, which doesn't exist. Building it using --with-mysql-sock=/var/lib/mysql/mysql.sock should force both to be the same.

我在CentOS 6上发现了PHP,它是由mysql.default_socket=/var/lib/mysql/mysql.sock构建的,但是由于某些原因pdo_mysql.default_socket=/tmp/mysql.sock不存在。建筑使用——with-mysql-sock = / var / lib / mysql / mysql。袜子应该迫使两者都是一样的。

Alternatively edit php.ini to contain:

或者编辑php。ini控制:

pdo_mysql.default_socket="/var/lib/mysql/mysql.sock"

...or your correct socket location, of course.

…或者你正确的插座位置,当然。

#5


4  

i fixed it like this.Just add a line. in laravel project APP=>Config=>database.php update the
Connections=>mysql after strict add below line

我是这样固定的。只是添加一行。在laravel项目应用= >配置= >数据库。php更新连接=>mysql后,严格添加以下行

'unix_socket' => "/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock"

sample:-

示例:

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
            'unix_socket' => "/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock"
        ],

#6


0  

This happened to me out of nowhere, my app (Laravel) was working fine yesterday and dropped today with this error (SQLSTATE[HY000] [2002] No such file or directory).

这在我身上发生了,我的应用程序(Laravel)昨天运行得很好,但今天却出现了这个错误(SQLSTATE[HY000][2002],没有这样的文件或目录)。

After checking that my config file had not been not corrupted, I connected to my control panel (I am using a VPS) and restarted MySQL server. That did the trick, everything is back online.

在检查我的配置文件没有被损坏之后,我连接到我的控制面板(我正在使用VPS)并重新启动MySQL服务器。成功了,一切都恢复了。

#7


0  

Found the solution for Ampps user:
I had the same issue and I did a lot of searches but couldn't solve the issue until I looked at my MySql config file. In my config file socket was in line 21 and the path was
"/Applications/AMPPS/var/mysql.sock"

找到了Ampps用户的解决方案:我遇到了同样的问题,我进行了大量的搜索,但是直到我查看MySql配置文件后才发现问题。在我的配置文件套接字是在第21行,路径是"/Applications/AMPPS/var/mysql.sock"

In Ampps application click on MySql tab and then click on configuration button.

在Ampps应用程序中,单击MySql选项卡,然后单击configuration按钮。

You can also find the config file in "/Applications/AMPPS/mysql/etc" folder

您还可以在“/Applications/AMPPS/mysql/etc”文件夹中找到配置文件

So simply I added
'unix_socket' => '/Applications/AMPPS/var/mysql.sock',
to my database.php in mysql array and it's worked for me.
After host line. I have tested with localhost and 127.0.0.1 and both worked
Hopefully it's working for you too.

所以我只添加了'unix_socket' => '/ application /AMPPS/var/mysql。袜子,我的数据库。php在mysql数组中,它对我很有用。之后主机线。我已经用localhost和127.0.0.1进行了测试,它们都运行良好,希望对您也适用。

#1


43  

I had a similar error. I am using MAMP and what solved my issue was:

我也有类似的错误。我正在使用MAMP,解决我的问题的是:

  1. creating a symbolic link in: /var/mysql (create the directory if it does not exist)
  2. 在:/var/mysql中创建一个符号链接(如果目录不存在就创建它)
  3. cd /var/mysql && sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock
  4. cd /var/mysql & sudo ln -s / application /MAMP/tmp/mysql/mysql.sock

#2


7  

For users which are looking for a solution on XAMPP (Tested and worked on Mac OS X),

对于正在寻找XAMPP解决方案的用户(在Mac OS X上测试和工作),

Open terminal and create a symbolic link :

打开终端,创建一个符号链接:

sudo mkdir /var/mysql
cd /var/mysql
sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

Others solutions explained here : http://pravams.com/2011/05/26/magento-pdo-exception/

其他解决方案如下:http://pravams.com/2011/05/26/magento-pdo-exception/

#3


6  

After searching, I found this post:

搜索之后,我找到了这个帖子:

Setting up Laravel on a Mac php artisan migrate error: No such file or directory

在Mac php artisan上设置Laravel迁移错误:没有这样的文件或目录

Once I added

一旦我添加

'unix_socket' => '/tmp/mysql.sock’,

to my database.php in the mysql array, it worked. Not sure exactly why that works, but it does.

我的数据库。在mysql数组中,它起作用了。不知道为什么会这样,但确实如此。

#4


5  

I found PHP on CentOS 6 built with mysql.default_socket=/var/lib/mysql/mysql.sock yet for some reason pdo_mysql.default_socket=/tmp/mysql.sock, which doesn't exist. Building it using --with-mysql-sock=/var/lib/mysql/mysql.sock should force both to be the same.

我在CentOS 6上发现了PHP,它是由mysql.default_socket=/var/lib/mysql/mysql.sock构建的,但是由于某些原因pdo_mysql.default_socket=/tmp/mysql.sock不存在。建筑使用——with-mysql-sock = / var / lib / mysql / mysql。袜子应该迫使两者都是一样的。

Alternatively edit php.ini to contain:

或者编辑php。ini控制:

pdo_mysql.default_socket="/var/lib/mysql/mysql.sock"

...or your correct socket location, of course.

…或者你正确的插座位置,当然。

#5


4  

i fixed it like this.Just add a line. in laravel project APP=>Config=>database.php update the
Connections=>mysql after strict add below line

我是这样固定的。只是添加一行。在laravel项目应用= >配置= >数据库。php更新连接=>mysql后,严格添加以下行

'unix_socket' => "/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock"

sample:-

示例:

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
            'unix_socket' => "/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock"
        ],

#6


0  

This happened to me out of nowhere, my app (Laravel) was working fine yesterday and dropped today with this error (SQLSTATE[HY000] [2002] No such file or directory).

这在我身上发生了,我的应用程序(Laravel)昨天运行得很好,但今天却出现了这个错误(SQLSTATE[HY000][2002],没有这样的文件或目录)。

After checking that my config file had not been not corrupted, I connected to my control panel (I am using a VPS) and restarted MySQL server. That did the trick, everything is back online.

在检查我的配置文件没有被损坏之后,我连接到我的控制面板(我正在使用VPS)并重新启动MySQL服务器。成功了,一切都恢复了。

#7


0  

Found the solution for Ampps user:
I had the same issue and I did a lot of searches but couldn't solve the issue until I looked at my MySql config file. In my config file socket was in line 21 and the path was
"/Applications/AMPPS/var/mysql.sock"

找到了Ampps用户的解决方案:我遇到了同样的问题,我进行了大量的搜索,但是直到我查看MySql配置文件后才发现问题。在我的配置文件套接字是在第21行,路径是"/Applications/AMPPS/var/mysql.sock"

In Ampps application click on MySql tab and then click on configuration button.

在Ampps应用程序中,单击MySql选项卡,然后单击configuration按钮。

You can also find the config file in "/Applications/AMPPS/mysql/etc" folder

您还可以在“/Applications/AMPPS/mysql/etc”文件夹中找到配置文件

So simply I added
'unix_socket' => '/Applications/AMPPS/var/mysql.sock',
to my database.php in mysql array and it's worked for me.
After host line. I have tested with localhost and 127.0.0.1 and both worked
Hopefully it's working for you too.

所以我只添加了'unix_socket' => '/ application /AMPPS/var/mysql。袜子,我的数据库。php在mysql数组中,它对我很有用。之后主机线。我已经用localhost和127.0.0.1进行了测试,它们都运行良好,希望对您也适用。