MySQL 无法启动 phpMyAdmin。不断收到 #2002 套接字错误

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

Can't start phpMyAdmin. Keep getting the #2002 socket error

mysqlmacossocketsphpmyadmin

提问by Stella Antonova

I've been trying to set mysql and phpMyAdmin for the last 12 hours, without any success. And yes, after hours and hours of Google-ing I know that is a common problem and I've read similar queries on stackoverflow but still can't come with the solution.....

在过去的 12 小时内,我一直在尝试设置 mysql 和 phpMyAdmin,但没有成功。是的,经过数小时的 Google 搜索后,我知道这是一个常见问题,并且我已经阅读过有关 stackoverflow 的类似查询,但仍然无法提供解决方案.....

I've tried everything - from changing the

我已经尝试了一切 - 从改变

$cfg['Servers'][$i]['port']

in the config.inc.phpfile to 3306, 127.0.0.1....

config.inc.php文件中3306127.0.0.1....

typing the socket path in the config.inc.phpfile - both tmp/mysql.phpand the /var/mysql/mysql.sock.

config.inc.php文件中输入套接字路径- tmp/mysql.php/var/mysql/mysql.sock.

I've tried changing the socket path in the my.cnf file and the php.ini....but I keep getting the same error:

我已经尝试更改 my.cnf 文件和 php.ini 中的套接字路径......但我一直收到相同的错误:

#2002 - No such file or directory
The server is not responding (or the local server's socket is not correctly configured).

I'm using MySQL (5.1.65), PhpMyAdmin (3.5.2.2) and PHP (5.3.8).

我正在使用 MySQL (5.1.65)、PhpMyAdmin (3.5.2.2) 和 PHP (5.3.8)。

回答by natterstefan

I have recently encountered this problem on Mac OS Sierra too. Apache server is working but mysql is not. After searching for a solution, reading lots of posts I found this solution. And it worked!

我最近也在 Mac OS Sierra 上遇到了这个问题。Apache 服务器正在工作,但 mysql 没有。在寻找解决方案后,阅读了很多帖子,我找到了这个解决方案。它奏效了!

The solution is to navigate to the mysql folder, in my case its,

解决方案是导航到 mysql 文件夹,在我的情况下,

/Applications/MAMP/db/mysql56/

/Applications/MAMP/db/mysql56/

and remove all the files except folders. Then restart MAMP again.

并删除除文件夹之外的所有文件。然后再次重新启动 MAMP。

回答by andrewoodleyjr

  1. Quit MAMP
  2. Open the terminal
  3. Type: killall -9 mysqld Restart MAMP
  1. 退出 MAMP
  2. 打开终端
  3. 类型:killall -9 mysqld 重启MAMP

回答by swedge218

Since you did not mention MAMP, I am assuming you are not using it so this is for a manual install but it will likely also work for MAMP.

由于您没有提到 MAMP,我假设您没有使用它,因此这是手动安装,但它可能也适用于 MAMP。

In my experience, this is caused by the socket variable of your mysql. By default, MySQL uses /tmp/mysql.sock.

根据我的经验,这是由您的 mysql 的套接字变量引起的。默认情况下,MySQL 使用 /tmp/mysql.sock。

You can get the MySQL socket variable by logging into your MySQL and doing

您可以通过登录 MySQL 并执行以下操作来获取 MySQL 套接字变量

show variables like '%socket%'

that will show you the location of the socket file.

这将显示套接字文件的位置。

Now, create a php phpinfo() file and look for mysql.default_socket under the mysql or mysqli section. Mine was /var/mysql/mysql.sock. This shows that PHP is looking for the file in a different location than mysql is using.

现在,创建一个 php phpinfo() 文件并在 mysql 或 mysqli 部分下查找 mysql.default_socket 。我的是/var/mysql/mysql.sock。这表明 PHP 正在与 mysql 使用的位置不同的位置查找文件。

Assuming you have same values, open new terminal and enter

假设你有相同的值,打开新终端并输入

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

this will create a link to the mysql socket file inside the location PHP is checking from.

这将创建一个链接到 PHP 正在检查的位置内的 mysql 套接字文件。

PHPMyAdmin should work now.

PHPMyAdmin 现在应该可以工作了。

回答by Steve Tauber

The problem I had with this was because PHP was trying to connect via a UNIX socket instead of TCP. This is similar to this error: Error when connecting to MySQL using PHP/PDO

我遇到的问题是因为 PHP 试图通过 UNIX 套接字而不是 TCP 进行连接。这类似于这个错误:Error when connected to MySQL using PHP/PDO

First, make sure you have a my.cnf config for mysql then add your default socket location:

首先,确保您有一个用于 mysql 的 my.cnf 配置,然后添加您的默认套接字位置:

[mysqld_safe] socket = /tmp/mysql.sock

Next in your php.ini, let PHP know where it is:

接下来在你的 php.ini 中,让 PHP 知道它在哪里:

mysql.default_socket = /tmp/mysql.sock

回答by Sadee

Check the config file:

检查配置文件:

/* $cfg['Servers'][$i]['host'] = 'localhost'; */
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['compress'] = false;

Restart MySQL: OSx : sudo /usr/local/mysql/support-files/mysql.server restart

重启 MySQL: OSx : sudo /usr/local/mysql/support-files/mysql.server restart

Linux: sudo service mysql start(Old linux: sudo /etc/init.d/mysql start)

Linux : sudo service mysql start(旧的 linux: sudo /etc/init.d/mysql start)

回答by Lasithds

If you are using homebrew restart mariadb. I also had the same issue and after stopping and starting mariadb it started working again.

如果您使用的是自制软件,请重新启动 mariadb。我也遇到了同样的问题,在停止并启动 mariadb 后,它又开始工作了。

brew services restart mariadb

brew services restart mariadb

回答by AppEmmanuel

Am using MAMP on a macbook pro running High Sierra, and in my case, I tried all the above but it still did not work for me so I did the following :

在运行 High Sierra 的 macbook pro 上使用 MAMP,就我而言,我尝试了上述所有方法,但仍然对我不起作用,因此我执行了以下操作:

  1. Looking for where you installed your MAMP and more specifically, look for the "config.inc.php" file located in "/Applications/MAMP/bin/phpMyAdmin".
  1. 查找 MAMP 的安装位置,更具体地说,查找位于“/Applications/MAMP/bin/phpMyAdmin”中的“config.inc.php”文件。

enter image description here

在此处输入图片说明

  1. Backup (ie. on a mac, right click and duplicate) the "config.inc.php" file before we touch it. You can call or rename it "config_old.inc.php"

  2. Open the file in your favorite IDE or text editor.

  1. 在我们触摸它之前备份(即在 Mac 上,右键单击并复制)“config.inc.php”文件。您可以调用或重命名为“config_old.inc.php”

  2. 在您喜欢的 IDE 或文本编辑器中打开文件。

enter image description here

在此处输入图片说明

  1. Look for the following lines ;
  1. 寻找以下几行;

i) $cfg['Servers'][$i]['host']

i) $cfg['Servers'][$i]['host']

ii) $cfg['Servers'][$i]['port']

ii) $cfg['Servers'][$i]['port']

iii) $cfg['Servers'][$i]['socket']

iii) $cfg['Servers'][$i]['socket']

Change from :

更改自:

$cfg['Servers'][$i]['host'] = 'localhost';

to :

到 :

$cfg['Servers'][$i]['host'] = '127.0.0.1';

Change from :

更改自:

$cfg['Servers'][$i]['port'] = '3306';

/this might be your default. Just check to see from your MAMP installation preference , press CMD + , and confirm that port number you have specified. In my case I had changed it to 8889./

/这可能是您的默认设置。只需检查您的 MAMP 安装首选项,按 CMD + 并确认您指定的端口号。在我来说,我已经把它改为8889/

enter image description here

在此处输入图片说明

to :

到 :

$cfg['Servers'][$i]['port'] = '8889';

Again depending on where you installed your MAMP or to be more specific your mysql.

再次取决于您安装 MAMP 的位置或更具体的 mysql。

Change from :

更改自:

$cfg['Servers'][$i]['socket'] = 'some_folder_path or EMPTY';

to :

到 :

$cfg['Servers'][$i]['socket'] = '/Applications/MAMP/Library/bin/mysql/mysql.sock';

After this modification, save and refresh in your web browser.

在此修改后,在您的 Web 浏览器中保存并刷新。

Worked for me. Hope this helps. Cheers.

为我工作。希望这可以帮助。干杯。

回答by user8131038

Had this problem on Windows 7 Ultimate, AppServ. Just reload SQL and Apache (but you need to reload both of them, reloading only Apache didn't worked).

在 Windows 7 Ultimate、AppServ 上有这个问题。只需重新加载 SQL 和 Apache(但您需要重新加载它们,仅重新加载 Apache 不起作用)。

PHPMyAdmin 4.6.6
Server: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
Server version: 5.7.17-log - MySQL Community Server (GPL)
PHP: 5.6.30

回答by B. Zakariaa

check that mysql-serveralready installed if not sudo apt-get install mysql-server

mysql-server如果没有,请检查是否已安装 sudo apt-get install mysql-server