繁体   English   中英

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

[英]Fix Access denied for user 'root'@'localhost' for phpMyAdmin

我在 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.

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

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

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

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

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

并将其替换为

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

我有同样的问题我已经在数据库中更改密码后..我所做的就是前面我已经改变了更新密码的编辑,我并没有在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'] = '';

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

转到并编辑文件

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

找线

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

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

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

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

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

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

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

将上面的行更改为:

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

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

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

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

并将其替换为

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

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

我所做的正是:

  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步

突然它起作用了!

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

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

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

这些是:-

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

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

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

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

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

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

127.0.0.1  localhost
::1        localhost

要解决上述错误:-

a)  Open Mysql console from the tray of WAMP server

b)  It will ask for a password(you might have set this password earlier when u installed MySql in your system)(In my case it is admin)

c)  Enter admin (press enter)

现在这意味着您的 PhpMyAdmin 假设您的 MySql 没有密码并且无法连接 MySql,但是您可以通过提供密码来连接您的 MySql 服务器,此打开 config.inc 文件来自以下路径

C:\\wamp\\apps\\phpmyadmin4.1.14

并替换这一行

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

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

我希望它会起作用...

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

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

我还补充道:

$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.

我在phi.ini中添加了这个

session.gc_maxlifetime=150000

什么对我有用:

转到 config.inc.php。

改变

$cfg['Servers'][$i]['AllowNoPassword'] = true;

$cfg['Servers'][$i]['AllowNoPassword'] = false;

改变

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

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

改变

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

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

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

类型:根
通过:(空)

现在您可以访问它。 :)

我使用此 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'] = '';

此更改为我解决了错误

$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;

然后

sudo service mysql stop
/opt/lampp/lampp start

并解决了问题

xampp\\phpMyAdmin/config.inc

查找-

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

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

还要注意“setup”(即localhost/phpmyadmin/setup)在处理“无密码”选项的方式上有错误。 虽然它创建了一行,上面写着:

$cfg['Servers'][$i]['nopassword'] = true;

参数的实际名称应如下所示:

$cfg['Servers'][$i]['AllowNoPassword'] = true;

截至 2015 年 10 月 20 日,此“设置”错误仍存在。

尝试找到 $cfg['Servers'][$i]['password'] = ''; 在位于 wamp/scripts/config.inc.php 的配置文件中

然后将密码设置为你的mysql密码并刷新PhpmyAdmin

我也遇到了这个问题

我发现 phpmyadmin 的配置文件中的密码字段为空。 我把我填入数据库设置的密码。 现在它工作正常

我在使用 XAMPP 和 phpMyAdmin 时遇到了同样的问题,这就是我轻松解决的方法。


1.打开XAMPP控制面板
2.然后选择右侧的资源管理器按钮


3.然后它将导航到配置所在的位置,您必须
进入 phpMyAdmin 文件夹,然后右键单击突出显示的文件夹并在任何文本编辑器上选择编辑选项



4.然后只编辑以下四舍五入部分作为您的MySQL服务器用户名和密码
如果您的 MySQL 服务器用户名是root并且
如果您的 MySQL 服务器密码是root ,请保留图像中的密码

根据您提供给 MySQL 服务器的用户名和密码更改它们



5. 保存更改并打开浏览器并粘贴
http://localhost/phpmyadmin/index.php
导航到 phpMyAdmin

有时配置并不总是问题所在。

尝试检查 MySql 配置。 如果你改变了端口号。 在 mysql 上对 PHP 配置php.ini进行类似的更改。 查找并替换必要的更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM