【问题标题】:Fix Access denied for user 'root'@'localhost' for phpMyAdmin修复 phpMyAdmin 用户 'root'@'localhost' 的访问被拒绝
【发布时间】:2013-10-29 05:28:20
【问题描述】:

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

【问题讨论】:

  • 特权是特定于主机的
  • 编辑您的%windir%\system32\drivers\etc\hosts 文件并在其中添加/取消注释127.0.0.1 localhost
  • 有时可以通过清除所有 cookie 来修复 phpMyAdmin 的登录问题。
  • @xyz,您的评论解决了我的问题。我被卡住了,浪费了我的半天时间。

标签: php mysql phpmyadmin wamp


【解决方案1】:

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

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

替换成

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

【讨论】:

  • 这对我有用。非常感谢。我正在使用 XAMPP,所以文件的目录是 {Drive(C:/ or D:/ 或 XAMPP 文件夹所在的任何位置)}xampp\phpMyAdmin\config.inc.php 并按照 Nikhil 的说明进行操作。
  • 这里我有一个建议可以让这个解决方案更流畅。在最后一行代码之后,您还可以添加 $cfg['Servers'][$i]['AllowNoPassword'] = true;
  • 简短而有效的答案。谢谢!
  • 在这个配置文件中不存在类似$cfg['Servers'][$i]['password'] 的东西...
  • 温馨提示:对于 W7 上的 XAMPP,文件为 /xampp/phpMyAdmin/config.inc.php
【解决方案2】:

更改数据库中的密码后,我遇到了同样的问题。我所做的是 我之前更改的更新密码的编辑,我没有在 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'] = '';

【讨论】:

  • 这发生在我身上,因为我从 mysql 内部更改了我的 root 用户的密码。我只需要更新config.inc 内部的密码(我的是config.inc.php),它对我有用。
  • 是的,您需要同步所有文件的更新,因为它们相互依赖。
【解决方案3】:

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

转到并编辑文件

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

找线

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

并将 'config' 更改为 'http',这样您就可以在使用浏览器访问 phpMyAdmin 页面时输入用户名和密码。

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

【讨论】:

    【解决方案4】:

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

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

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

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

    将上面的行改为:

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

    【讨论】:

    • 这是工作的时候,先停止正在运行的 Apache 和 MySql,然后到上面的步骤。
    【解决方案5】:

    如果你有mysql的密码,那么写如下:

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

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

    替换成

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

    【讨论】:

      【解决方案6】:

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

      我所做的是:

      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 步

      突然间它起作用了!

      【讨论】:

      • 最 APT 和 EXACT 解决方案
      【解决方案7】:

      什么对我有用:

      转到 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

      类型:根
      通过:(空)

      现在您可以访问它了。 :)

      【讨论】:

        【解决方案8】:

        @Dagon 的想法是正确的,但在细节上有点不足。

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

        这是因为在 MySQL 中,每个用户 ID 都与一个主机相关联,即允许用户登录的 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
        

        【讨论】:

        • 添加::1 localhost 是我的完美解决方案。非常感谢!
        【解决方案9】:

        解决上述错误:-

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

        我希望它会工作......

        【讨论】:

          【解决方案10】:

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

          我认为使用带有 $cfg['Servers'][$i]['auth_type'] = 'cookie'; 的 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
          

          【讨论】:

            【解决方案11】:

            我使用此 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
            

            问题解决了

            【讨论】:

              【解决方案12】:

              xampp\phpMyAdmin/config.inc

              寻找-

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

              并将“config”更改为“http”,这样您就可以在使用浏览器访问 phpMyAdmin 页面时输入用户名和密码。

              【讨论】:

                【解决方案13】:

                还要注意“设置”(即 localhost/phpmyadmin/setup)在处理“无密码”选项的方式上存在错误。虽然它会创建一行内容:

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

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

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

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

                【讨论】:

                【解决方案14】:

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

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

                【讨论】:

                  【解决方案15】:

                  我也遇到过这个问题,

                  我发现 phpmyadmin 的配置文件中的密码字段为空白。我输入了我在数据库设置中填写的密码。现在一切正常

                  【讨论】:

                    【解决方案16】:

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


                    1.打开XAMPP控制面板
                    2.然后选择右边的Explorer Button


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



                    4. 然后只编辑 MySQL 服务器用户名和密码的以下圆角部分
                    如果您的 MySQL 服务器用户名是 root 并且
                    如果您的 MySQL 服务器密码是 root,请保持图片原样

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



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

                    【讨论】:

                      【解决方案17】:

                      有时配置并不总是问题。

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

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 2012-07-14
                        • 2013-12-06
                        • 1970-01-01
                        • 2013-07-28
                        • 2023-03-20
                        • 2017-10-04
                        相关资源
                        最近更新 更多