MySQL phpMyAdmin 抛出#2002 无法登录mysql服务器phpmyadmin

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

phpMyAdmin is throwing a #2002 cannot log in to the mysql server phpmyadmin

mysqlphpmyadmin

提问by narancha

I have installed MySQL server enterprise 5.1 on my local machine and now I want to install phpMyAdmin, but it does not work.

我已经在本地机器上安装了 MySQL 服务器企业 5.1,现在我想安装 phpMyAdmin,但它不起作用。

I have unrared phpMyAdmin to my server root directory and browsed to "localhost/phpMyAdmin/setup/index.php", started a new server and the only setting I changed was filling in my MySQL password in the field "Password for config auth"

我已将 phpMyAdmin 解压到我的服务器根目录并浏览到“localhost/phpMyAdmin/setup/index.php”,启动了一个新服务器,我更改的唯一设置是在“配置身份验证密码”字段中填写我的 MySQL 密码

So now when I am trying to log in I get an error message saying "#2002 cannot log in to the mysql server phpmyadmin"

所以现在当我尝试登录时,我收到一条错误消息“#2002 无法登录到 mysql 服务器 phpmyadmin”

Does anyone know what's wrong? I've been having this problem since yesterday.

有谁知道出了什么问题?我从昨天开始就遇到这个问题。

回答by kouton

If you're getting the #2002 Cannot log in to the MySQL servererror while logging in to phpmyadmin, try editing phpmyadmin/config.inc.phpand change:

如果您在#2002 Cannot log in to the MySQL server登录 phpmyadmin 时遇到错误,请尝试编辑phpmyadmin/config.inc.php和更改:

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

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

to:

到:

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

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

Solution from Ryan's blog

来自Ryan 博客的解决方案

Edit (20-Mar-2015):

编辑(2015 年 3 月 20 日):

Note that if you're on a fresh install, config.inc.php may not exist. You need to rename / copy config.sample.inc.php and then change the relevant line

请注意,如果您是全新安装,则 config.inc.php 可能不存在。您需要重命名/复制 config.sample.inc.php 然后更改相关行

回答by Vladimir

This is old but as it is the first result in Google,

这是旧的但因为它是谷歌的第一个结果,

Please note that this also happens when your MySql service is down,

请注意,这也会在您的 MySql 服务关闭时发生,

I fixed this by simply restarting MySQL Server using:

我通过简单地使用以下命令重新启动 MySQL 服务器来解决这个问题:

/etc/init.d/mysql restart

/etc/init.d/mysql restart

in SSH (Command is for a CentOS/CPanel server)

在 SSH 中(命令用于 CentOS/CPanel 服务器)

回答by Knight

Background: I am using Linux Mint 13. In my case, this error happened when I restarted the computer and my DHCP assigned a new local IP address (from 192.168.0.2 to 192.168.0.4) to my desktop.

背景:我使用的是 Linux Mint 13。就我而言,当我重新启动计算机并且我的 DHCP 为我的桌面分配了一个新的本地 IP 地址(从 192.168.0.2 到 192.168.0.4)时,发生了这个错误。

sudo gedit /etc/mysql/my.cnf

Update

更新

bind-address = 192.168.0.2

to

bind-address = localhost

This fixed the problem. Enjoy.

这解决了问题。享受。

回答by Geoffrey Booth

This can also be caused if you forget (as I did) to move config.inc.phpinto its proper place after completing the setup script.

如果您config.inc.php在完成安装脚本后忘记(就像我一样)移动到正确的位置,也可能会导致这种情况。

After making the configfolder and doing chmod o+rw configand going to localhost/phpmyadmin/setupand following those steps, you need to go back to the command line and finish things off:

创建config文件夹并执行chmod o+rw configlocalhost/phpmyadmin/setup执行这些步骤后,您需要返回命令行并完成以下操作:

mv config/config.inc.php .         # move file to current directory
chmod o-rw config.inc.php          # remove world read and write permissions
rm -rf config                      # remove not needed directory

See full instructions at https://phpmyadmin.readthedocs.org/en/latest/setup.html

请参阅https://phpmyadmin.readthedocs.org/en/latest/setup.html 上的完整说明

回答by jookyone

After trying all of the above suggestions here is what fixed my #2002 error.

在尝试了以上所有建议之后,修复了我的 #2002 错误。

Add the following line to your config.inc.php file and change the number to your MySQL port:

将以下行添加到您的 config.inc.php 文件并将数字更改为您的 MySQL 端口:

$cfg['Servers'][$i]['port'] = '3307'; // MySQL port

I had multiple mysql instances installed, and in this case, I had updated my.ini to run MySQL on port 3307, but had not updated phpMyAdmin to reflect the new port. In my case, the line for the port did not exist in the config.inc.php file, so I was not aware that it needed updating.

我安装了多个 mysql 实例,在这种情况下,我更新了 my.ini 以在端口 3307 上运行 MySQL,但没有更新 phpMyAdmin 以反映新端口。就我而言,端口行在 config.inc.php 文件中不存在,所以我不知道它需要更新。

回答by amphetamachine

Did you set up the MySQL on your machine? It sounds like you're using Windows; MySQL runs as a "Service" on your machine (right-click My Computer -> Manage -> Services).

您是否在您的机器上设置了 MySQL?听起来您正在使用 Windows;MySQL 在您的计算机上作为“服务”运行(右键单击我的电脑 -> 管理 -> 服务)。

回答by mbommel

I've been through basically all of stackoverflow for this error and nothing resolved my issue. I was able to log into mysql directly from the linux command line fine, but with the same user and password couldn't log into phpmyadmin.

对于这个错误,我基本上已经完成了所有的stackoverflow,但没有解决我的问题。我能够直接从 linux 命令行登录到 mysql,但是使用相同的用户和密码无法登录到 phpmyadmin。

So I beat my head against the wall for half the day until I realized it wasn't even reading the config.inc.php under /etc/phpmyadmin (the only place it was located btw based on "find / -iname config.inc.php". So I changed the host in /usr/share/phpMyAdmin/libraries/config.default.php and it finally worked.

所以我把头撞在墙上半天,直到我意识到它甚至没有读取 /etc/phpmyadmin 下的 config.inc.php(它位于 btw 的唯一位置基于“find / -iname config.inc .php”。所以我更改了 /usr/share/phpMyAdmin/libraries/config.default.php 中的主机,它终于工作了。

I know there's probably another issue with why it isn't reading the config from the /etc/phpmyadmin folder but I can't be bothered with that for now :P

我知道为什么它不从 /etc/phpmyadmin 文件夹中读取配置可能还有另一个问题,但我现在不能为此烦恼:P

tldr; if your settings don't seem to be applying at all try making the changes within /usr/share/phpMyAdmin/libraries/config.default.php

tldr; 如果您的设置似乎根本不适用,请尝试在 /usr/share/phpMyAdmin/libraries/config.default.php 中进行更改

回答by Eka Wijaya

I have also experienced the same thing, hopefully a this helps.

我也经历过同样的事情,希望这会有所帮助。

cd /etc/init.d
./mysql start

please login to access mysql and phpmyadmin

请登录访问mysql和phpmyadmin

回答by driftking9987

It happened with me when I changed the instance type of my AWS server.

当我更改 AWS 服务器的实例类型时,它发生在我身上。

#2002 Cannot log in to the MySQL servercan also occur when the mysqldservice is not started.

#2002 Cannot log in to the MySQL servermysqld服务未启动时也可能发生。

So first of all you need to execute :

所以首先你需要执行:

$ sudo service mysqld restart

This will give you :

这会给你:

$ sudo service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

After that the error will not come.

之后错误就不会来了。

P.S. On EC2 instances, one should also change the host from localhostto 127.0.0.1as mentioned in the top answer.

PS 在 EC2 实例上,还应该将主机从 更改为localhost127.0.0.1如顶部答案中所述。

回答by Vikram

In my system, config.inc.phpdidn't exist, but config.sample.inc.phpexisted. Try copying the sample script to config.inc.php

在我的系统中,config.inc.php不存在,但config.sample.inc.php存在。尝试将示例脚本复制到config.inc.php