php 修复 phpMyAdmin 用户 'root'@'localhost' 拒绝访问的问题

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

Fix Access denied for user 'root'@'localhost' for phpMyAdmin

phpmysqlphpmyadminwamp

提问by Luke

I'm using WAMP Server 2.2 on a PC. In phpMyAdmin (version 5.5.24) I edited the 'root' user (with 'localhost' host) and gave it a password of 'root'. This turned out to be a big mistake that I'm trying to revert. Now when I go to localhost/phpmyadmin/I get the menu of databases on the left, but the main frame has an error that reads:

我在 PC 上使用 WAMP Server 2.2。在 phpMyAdmin(5.5.24 版)中,我编辑了“root”用户(使用“localhost”主机)并给它一个密码“root”。结果证明这是一个我试图恢复的大错误。现在,当我转到localhost/phpmyadmin/ 时,我会看到左侧的数据库菜单,但是主框架有一个错误,内容如下:

#1045 - Access denied for user 'root'@'localhost' (using password: NO)
phpMyAdmin tried to connect to the MySQL server, and the server rejected the 
connection. You should check the host, username and password in your 
configuration and make sure that they correspond to the information given 
by the administrator of the MySQL server.

If I go to 127.0.0.1/phpmyadmin, I do notget the error and everything works fine.

如果我转到127.0.0.1/phpmyadmin,我不会收到错误并且一切正常。

I tried changing the user's password back to no password; I tried modifying config.inc.php file to add the new password (but that made phpMyAdmin error-out completely); I tried removing and recreating the root/localhost user. Nothing seems to work. The root/localhost user appears to have no password and all privileges, but the error remains.

我尝试将用户的密码改回无密码;我尝试修改 config.inc.php 文件以添加新密码(但这使 phpMyAdmin 完全出错);我尝试删除并重新创建 root/localhost 用户。似乎没有任何效果。root/localhost 用户似乎没有密码和所有权限,但错误仍然存​​在。

Any ideas or how I can get this user's access back to normal without having to reinstall WAMP?

有什么想法或如何使该用户的访问恢复正常而无需重新安装 WAMP?

回答by Nikhil G

Find config.incfile under C:\wamp\apps\phpmyadmin3.5.1Inside this file find this one line

在此文件内查找config.inc文件C:\wamp\apps\phpmyadmin3.5.1找到这一行

$cfg['Servers'][$i]['password'] =";

and replace it with

并将其替换为

$cfg['Servers'][$i]['password'] = 'Type your root password here';

回答by Ezra A.Mosomi

I had the same problem after i had changed the passwords in the database.. what i did was the editing of the updated password i had changed earlier and i didn't update in the config.inc.php and the same username under D:\xamp\phpMyAdmin\config.inc

我有同样的问题我已经在数据库中更改密码后..我所做的就是前面我已经改变了更新密码的编辑,我并没有在config.inc.php文件,并在相同的用户名更新d: \xamp\phpMyAdmin\config.inc

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = **'root'**;
$cfg['Servers'][$i]['password'] = **'epufhy**';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

回答by Syed Nazri bin Wan Ikhsan

After I change the password for my "root" in phpMyAdmin page, I had a same problem and also looking for the solutions from the internet but fail to get the answer I needed, so I check the documentation inside the phpMyAdmin directory.

在 phpMyAdmin 页面中更改“root”的密码后,我遇到了同样的问题,也在网上寻找解决方案,但没有得到我需要的答案,所以我查看了 phpMyAdmin 目录中的文档。

Go to and edit the file

转到并编辑文件

\modules\phpmyadmin414x140123114237\config.sample.inc.php

look for line

找线

$cfg['Servers'][$i]['auth_type'] = 'config'

and change the 'config'to 'http'and that will allow you to type the user name and password when you go to your phpMyAdmin page using your browser.

并将“配置”更改为“http”,这将允许您在使用浏览器访问 phpMyAdmin 页面时输入用户名和密码。

OR

或者

see the documentation file under the same phpMyAdmin directory (phpmyadmin414x140123114237\doc\html) for help and search for $cfg['Servers'][$i]['auth_type']and you will see 4 options to choose from as to how to login to your phpMyAdmin page.

请参阅同一 phpMyAdmin 目录 ( phpmyadmin414x140123114237\doc\html)下的文档文件以获取帮助和搜索$cfg['Servers'][$i]['auth_type'],您将看到 4 个选项可供选择,以了解如何登录到您的 phpMyAdmin 页面。

回答by shubham balyan

Locate config.inc.php file under C:\xampp\phpMyAdmin and open it in any editor. Find the following line:

在 C:\xampp\phpMyAdmin 下找到 config.inc.php 文件并在任何编辑器中打开它。找到以下行:

$cfg['Servers'][$i]['password'] = '  ';

Enter the chosen password inside the quotes. Also, in order to make localhost/phpmyadmin ask for a username and password, find the following line:

在引号内输入选择的密码。此外,为了让 localhost/phpmyadmin 要求输入用户名和密码,请找到以下行:

$cfg['Servers'][$i]['auth_type'] = 'config';

Change the above line to:

将上面的行更改为:

$cfg['Servers'][$i]['auth_type'] = 'cookie';

回答by Hazem Elraffiee

Well .. That seems very odd to me, but it suddenly worked!!

嗯..这对我来说似乎很奇怪,但它突然起作用了!!

What I did exactly was:

我所做的正是:

  1. Navigated to phpMyAdmin folder, and edited the file "config.inc.php"
  2. Looked for the line: $cfg['Servers'][$i]['password'] = '';
  3. Added any password between '', let's say '1234'
  4. Reloaded localhost/phpmyadmin & 127.0.0.1/phpmyadmin (both showed the same error)
  5. Reverted "config.inc.php" to the old state (removed the password)
  6. Re-did step 4
  1. 导航到 phpMyAdmin 文件夹,并编辑文件“config.inc.php”
  2. 寻找这一行: $cfg['Servers'][$i]['password'] = '';
  3. 在“”之间添加了任何密码,比如说“1234”
  4. 重新加载 localhost/phpmyadmin & 127.0.0.1/phpmyadmin(都显示相同的错误)
  5. 将“config.inc.php”恢复到旧状态(删除了密码)
  6. 重做第4步

And suddenly it worked!

突然它起作用了!

回答by nyxee

using $cfg['Servers'][$i]['auth_type'] = 'config';is insecure i think.

$cfg['Servers'][$i]['auth_type'] = 'config';我认为使用 是不安全的。

using cookies with $cfg['Servers'][$i]['auth_type'] = 'cookie';is better i think.

$cfg['Servers'][$i]['auth_type'] = 'cookie';我认为使用 cookie更好。

I also added:

我还补充道:

$cfg['LoginCookieRecall'] = true;

$cfg['LoginCookieValidity'] = 100440;

$cfg['LoginCookieStore'] = 0;  //Define how long login cookie should be stored in browser. Default 0 means that it will be kept for existing session. This is recommended for not trusted environments.
$cfg['LoginCookieDeleteAll'] = true; //If enabled (default), logout deletes cookies for all servers, otherwise only for current one. Setting this to false makes it easy to forget to log out from other server, when you are using more of them.

I added this in phi.ini

我在phi.ini中添加了这个

session.gc_maxlifetime=150000

回答by simer

If you have existing password for mysql then write as mentioned below :

如果您有 mysql 的现有密码,请按如下所述写:

Find config(dot)inc file under C:\wamp\apps\phpmyadmin3.5.1Inside this file find this one line

C:\wamp\apps\phpmyadmin3.5.1下找到 config(dot)inc 文件在这个文件里面找到这一行

$cfg['Servers'][$i]['password'] =";

$cfg['Servers'][$i]['password'] =";

and replace it with

并将其替换为

$cfg['Servers'][$i]['password'] = **'your-password'**;

$cfg['Servers'][$i]['password'] = **'your-password'**;

回答by RiggsFolly

@Dagon had the right idea but was a little short on details.

@Dagon 有正确的想法,但在细节上有点欠缺。

If you use the access 127.0.0.1/phpmyadminand have a close look at the Users that are setup in MysQL you should see 3 versions of the rootusername.

如果您使用访问权限127.0.0.1/phpmyadmin并仔细查看在 MySQL 中设置的用户,您应该会看到 3 个版本的root用户名。

This is because in MySQL each userid is associated with a HOST, i.e. The PC ( ip address ) that the user is allowed to sign in from. So your 3 `'root' userids are in fact the same userid which is allowed to signin from 3 seperate HOSTS. Normally out of the box the 'root' has 3 HOSTS setup, 127.0.0.1, localhost and ::1

这是因为在 MySQL 中,每个用户 ID 都与一个 HOST 相关联,即允许用户登录的 PC(IP 地址)。因此,您的 3 个“root”用户 ID 实际上是允许从 3 个单独的主机登录的相同用户 ID。通常开箱即用的“root”有 3 个 HOSTS 设置,127.0.0.1、localhost 和 ::1

These are :-

这些是 :-

localhost is an alias for THIS MACHINE created from your HOSTS file ( c:\windows\system32\drivers\etc\hosts )

localhost 是从您的 HOSTS 文件( c:\windows\system32\drivers\etc\hosts )创建的此机器的别名

127.0.0.1 is the IPv4 loopback ip address of THIS MACHINE

127.0.0.1 是这台机器的 IPv4 环回 IP 地址

::1 is the IPv6 loopback ip address of THIS MACHINE

::1 是这台机器的 IPv6 环回 IP 地址

What is probably happening to you is that you have set a password for [email protected] but not any of the others. Now your browser will 'arbtrarily' decide to use ::1 or 127.0.0.1 as the host ip so when it uses ::1 your login will fail.

您可能遇到的情况是您为 [email protected] 设置了密码,但没有为其他任何密码设置密码。现在您的浏览器将“任意”决定使用 ::1 或 127.0.0.1 作为主机 IP,因此当它使用 ::1 时,您的登录将失败。

So login using 127.0.0.1/phpmyadminand change all 3 'root' usernames to have the same password you should no longer see this problem.

因此,使用登录127.0.0.1/phpmyadmin并将所有 3 个“root”用户名更改为具有相同的密码,您应该不会再看到此问题。

Also make sure that your HOSTS file has these 2 entries

还要确保您的 HOSTS 文件有这 2 个条目

127.0.0.1  localhost
::1        localhost

回答by Muhammad Aqeel

I use this URL to enter phpMyAdmin http://localhost:2145/phpmyadminbut get the following error:
"phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server"
my config.inc.php file is

我使用此 URL 输入 phpMyAdmin http://localhost:2145/phpmyadmin但收到以下错误:
“phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝了连接。您应该检查您的主机、用户名和密码配置并确保它们与MySQL服务器管理员提供的信息相对应”
我的config.inc.php文件是

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['host'] = 'localhost:2145';
$cfg['Servers'][$i]['connect_type'] = 'cookie';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';

this change resolve the mistake for me

此更改为我解决了错误

$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;

and then

进而

sudo service mysql stop
/opt/lampp/lampp start

and problem solved

并解决了问题

回答by debeka

What worked for me:

什么对我有用:

Go to config.inc.php

转到 config.inc.php

Change $cfg['Servers'][$i]['AllowNoPassword'] = true; to $cfg['Servers'][$i]['AllowNoPassword'] = false;

更改 $cfg['Servers'][$i]['AllowNoPassword'] = true; 到 $cfg['Servers'][$i]['AllowNoPassword'] = false;

Change $cfg['Servers'][$i]['password'] = '';

更改 $cfg['Servers'][$i]['password'] = '';

to

$cfg['Servers'][$i]['password'] = ' ';

$cfg['Servers'][$i]['password'] = ' ';

Change

改变

$cfg['Servers'][$i]['auth_type'] = 'config';

$cfg['Servers'][$i]['auth_type'] = 'config';

to

$cfg['Servers'][$i]['auth_type'] = 'http';

$cfg['Servers'][$i]['auth_type'] = 'http';

Reload the page http://localhost/phpmyadmin

重新加载页面http://localhost/phpmyadmin

Type : root pass : (empty)

类型:根通行证:(空)

Now you have access to it. :)

现在您可以访问它。:)