简体   繁体   English

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

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

I'm using WAMP Server 2.2 on a PC.我在 PC 上使用 WAMP Server 2.2。 In phpMyAdmin (version 5.5.24) I edited the 'root' user (with 'localhost' host) and gave it a password of 'root'.在 phpMyAdmin(版本 5.5.24)中,我编辑了“root”用户(使用“localhost”主机)并给它一个密码“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:现在,当我转到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 not get 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);我尝试修改 config.inc.php 文件以添加新密码(但这使 phpMyAdmin 完全出错); I tried removing and recreating the root/localhost user.我尝试删除并重新创建 root/localhost 用户。 Nothing seems to work.似乎没有任何效果。 The root/localhost user appears to have no password and all privileges, but the error remains. root/localhost 用户似乎没有密码和所有权限,但错误仍然存​​在。

Any ideas or how I can get this user's access back to normal without having to reinstall WAMP?有什么想法或如何使该用户的访问恢复正常而无需重新安装 WAMP?

Find config.inc file under C:\\wamp\\apps\\phpmyadmin3.5.1 Inside this file find this one lineC:\\wamp\\apps\\phpmyadmin3.5.1下找到config.inc文件在这个文件里面找到这一行

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

and replace it with并将其替换为

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

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

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 页面。

Locate config.inc.php file under C:\\xampp\\phpMyAdmin and open it in any editor.在 C:\\xampp\\phpMyAdmin 下找到 config.inc.php 文件并在任何编辑器中打开它。 Find the following line:找到以下行:

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

If you have existing password for mysql then write as mentioned below :如果您有 mysql 的现有密码,请按如下所述写:

Find config(dot)inc file under C:\\wamp\\apps\\phpmyadmin3.5.1 Inside this file find this one lineC:\\wamp\\apps\\phpmyadmin3.5.1下找到 config(dot)inc 文件在这个文件里面找到这一行

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

and replace it with并将其替换为

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

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

And suddenly it worked!突然它起作用了!

@Dagon had the right idea but was a little short on details. @Dagon 有正确的想法,但在细节上有点欠缺。

If you use the access 127.0.0.1/phpmyadmin and have a close look at the Users that are setup in MysQL you should see 3 versions of the root username.如果您使用访问127.0.0.1/phpmyadmin并仔细查看在 MySQL 中设置的用户,您应该会看到 3 个版本的root用户名。

This is because in MySQL each userid is associated with a HOST, ie The PC ( ip address ) that the user is allowed to sign in from.这是因为在 MySQL 中,每个用户 ID 都与一个 HOST 相关联,即允许用户登录的 PC(IP 地址)。 So your 3 `'root' userids are in fact the same userid which is allowed to signin from 3 seperate HOSTS.因此,您的 3 个“root”用户 ID 实际上是允许从 3 个单独的主机登录的相同用户 ID。 Normally out of the box the 'root' has 3 HOSTS setup, 127.0.0.1, localhost and ::1通常开箱即用的“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 root@127.0.0.1 but not any of the others.您可能遇到的情况是您为 root@127.0.0.1 设置了密码,但没有为其他任何密码设置密码。 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.现在您的浏览器将“任意”决定使用 ::1 或 127.0.0.1 作为主机 IP,因此当它使用 ::1 时,您的登录将失败。

So login using 127.0.0.1/phpmyadmin and 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

To resolve the above error:-要解决上述错误:-

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)

Now it means your PhpMyAdmin is assuming no password for your MySql and unable to connect MySql but you are able to connect your MySql Server by providing the password For this Open config.inc file from the below path现在这意味着您的 PhpMyAdmin 假设您的 MySql 没有密码并且无法连接 MySql,但是您可以通过提供密码来连接您的 MySql 服务器,此打开 config.inc 文件来自以下路径

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

And replace this line并替换这一行

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

to

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

I hope it will work...我希望它会起作用...

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

using cookies with $cfg['Servers'][$i]['auth_type'] = 'cookie';$cfg['Servers'][$i]['auth_type'] = 'cookie'; is better i think.我认为更好。

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

What worked for me:什么对我有用:

Go to config.inc.php.转到 config.inc.php。

Change改变

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

to

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

Change改变

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

to

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

Change改变

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

to

$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.现在您可以访问它。 :) :)

I use this URL to enter phpMyAdmin http://localhost:2145/phpmyadmin but get the following error:我使用此 URL 输入 phpMyAdmin http://localhost:2145/phpmyadmin但收到以下错误:
"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" “phpMyAdmin 尝试连接 MySQL 服务器,服务器拒绝连接。您应该检查配置中的主机、用户名和密码,并确保它们与 MySQL 服务器管理员提供的信息相对应”
my config.inc.php file is我的 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并解决了问题

xampp\\phpMyAdmin/config.inc xampp\\phpMyAdmin/config.inc

Find-查找-

$cfg['Servers'][$i]['auth_type'] = 'config' $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 页面时输入用户名和密码。

Also beware that "setup" (ie localhost/phpmyadmin/setup) has an error in the way it handles the "no password" option.还要注意“setup”(即localhost/phpmyadmin/setup)在处理“无密码”选项的方式上有错误。 While it creates a line that says:虽然它创建了一行,上面写着:

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

the actual name of the parameter should be as shown here:参数的实际名称应如下所示:

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

This "setup" error exists as of today, Oct 20, 2015.截至 2015 年 10 月 20 日,此“设置”错误仍存在。

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

Then set the password to your mysql password and refresh PhpmyAdmin然后将密码设置为你的mysql密码并刷新PhpmyAdmin

i also faced this problem,我也遇到了这个问题

i found password field was blank in config file of phpmyadmin.我发现 phpmyadmin 的配置文件中的密码字段为空。 i put that password which i filled in database settings.我把我填入数据库设置的密码。 now it is working fine现在它工作正常

I faced the same issue with XAMPP and phpMyAdmin and this is how I solved it easily.我在使用 XAMPP 和 phpMyAdmin 时遇到了同样的问题,这就是我轻松解决的方法。


1. Open the XAMPP control panel 1.打开XAMPP控制面板
2. Then select the Explorer Button on the right 2.然后选择右侧的资源管理器按钮


3. Then it will be navigated to the location where the configurations are and you have to 3.然后它将导航到配置所在的位置,您必须
go in side the phpMyAdmin folder and then right click on the highlighted folder and choose edit option on any text editor 进入 phpMyAdmin 文件夹,然后右键单击突出显示的文件夹并在任何文本编辑器上选择编辑选项



4. Then edit only the following rounded section as of your MySQL server username and password 4.然后只编辑以下四舍五入部分作为您的MySQL服务器用户名和密码
If your MySQL server username is root and 如果您的 MySQL 服务器用户名是root并且
If your MySQL server password is root , keep as of the image 如果您的 MySQL 服务器密码是root ,请保留图像中的密码

Change them according to your username and password which you have given to MySQL server 根据您提供给 MySQL 服务器的用户名和密码更改它们



5. Save the changes and open your browser and paste 5. 保存更改并打开浏览器并粘贴
http://localhost/phpmyadmin/index.php http://localhost/phpmyadmin/index.php
to navigate to phpMyAdmin 导航到 phpMyAdmin

Sometimes the config is not always the problem.有时配置并不总是问题所在。

Try checking the MySql config.尝试检查 MySql 配置。 If yuh have changed the port no.如果你改变了端口号。 on mysql make the similar changes to PHP config php.ini .在 mysql 上对 PHP 配置php.ini进行类似的更改。 Find and replace the necessary changes.查找并替换必要的更改。

暂无
暂无

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

相关问题 使用PHPMyAdmin拒绝用户“root”@“localhost”访问 - Access denied for user 'root'@'localhost' with PHPMyAdmin XAMPP PhpMyAdmin错误1045,“用户'root'@'localhost'的访问被拒绝 - XAMPP PhpMyAdmin Error 1045, "Access denied for user 'root'@'localhost' 在 ubuntu 上安装 phpmyadmin 后,用户“root”@“localhost”的访问被拒绝 - Access denied for user 'root'@'localhost' after installing phpmyadmin on ubuntu 用户root拒绝phpMyAdmin访问 - phpMyAdmin access denied for user root xampp localhost phpmyadmin 用户 'root'@'localhost' 访问被拒绝(使用密码:YES) - xampp localhost phpmyadmin Access denied for user 'root'@'localhost' (using password: YES) 用户“ @'localhost”的访问被拒绝(使用密码:NO)phpmyadmin - Access denied for user ''@'localhost' (using password: NO) phpmyadmin 我从 phpmyadmin 中删除了所有用户,现在它说'#1045 - 用户'root'@'localhost' 访问被拒绝(使用密码:NO)' - I deleted all the users from phpmyadmin and now it is saying '#1045 - Access denied for user 'root'@'localhost' (using password: NO)' Windows:#1045-用户'root'@'localhost'的访问被拒绝(使用密码:是)phpmyadmin - Windows: #1045 - Access denied for user 'root'@'localhost' (using password: YES) phpmyadmin 用户'root'@'localhost'的访问被拒绝(使用密码:NO) - Access denied for user 'root'@'localhost' (using password: NO) 无法连接:用户'root'@'localhost'的访问被拒绝 - Could not connect: Access denied for user 'root'@'localhost'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM