ChatGPT解决这个技术问题 Extra ChatGPT

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

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:

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

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.

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

privilages are host specific
Edit your %windir%\system32\drivers\etc\hosts file and add/uncomment 127.0.0.1 localhost in it
Sometimes login problems with phpMyAdmin can be fixed by clearing all of their cookies.
@xyz, your comment solved my issue. I was stuck and wasted my half day.

C
Community

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

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

and replace it with

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

This worked for me. Much thanks. I am using XAMPP so the directory of the file is {Drive(C:/ or D:/ Or whatever the XAMPP folder is located)}xampp\phpMyAdmin\config.inc.php and follow Nikhil's Instructions.
Here I have got a suggestion to make this solution more smooth. After that last line of code you can also add $cfg['Servers'][$i]['AllowNoPassword'] = true;
Short and efficient answer. Thank you!
Not exist anything like $cfg['Servers'][$i]['password'] in this config file ...
Good to know: For XAMPP on W7, the file is /xampp/phpMyAdmin/config.inc.php
E
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

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

This happened to me because I changed my root user's password from inside mysql. I just had to update the password inside of config.inc (mine was config.inc.php) and it worked for me.
Yes you need to synchronize the updates on all the files because they depend on each other.
T
Tony

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.

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.

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.


s
shubham balyan

Locate config.inc.php file under C:\xampp\phpMyAdmin and open it in any editor. 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:

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

Change the above line to:

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

this is working when, stop first the running Apache and MySql, then to the steps above.
a
ankitr

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

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

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

and replace it with

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


A
ArSeN

What worked for me:

Go to 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

Type : root pass : (empty)

Now you have access to it. :)


H
Hazem Elraffiee

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

What I did exactly was:

Navigated to phpMyAdmin folder, and edited the file "config.inc.php" Looked for the line: $cfg['Servers'][$i]['password'] = ''; Added any password between '', let's say '1234' Reloaded localhost/phpmyadmin & 127.0.0.1/phpmyadmin (both showed the same error) Reverted "config.inc.php" to the old state (removed the password) Re-did step 4

And suddenly it worked!


Most APT And EXACT Solution
R
RiggsFolly

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

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.

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

These are :-

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

127.0.0.1 is the IPv4 loopback ip address of THIS MACHINE

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

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

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.

Also make sure that your HOSTS file has these 2 entries

127.0.0.1  localhost
::1        localhost

Adding ::1 localhost was the perfect solution in my case. Thanks a ton!
G
Genes

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

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


n
nyxee

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

using cookies with $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

session.gc_maxlifetime=150000

M
Muhammad Aqeel

I use this URL to enter phpMyAdmin http://localhost:2145/phpmyadmin but 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

$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


N
Niroshan Ratnayake

I faced the same issue with XAMPP and phpMyAdmin and this is how I solved it easily.

go in side the phpMyAdmin folder

root

root

Change them according to your username and password which you have given to MySQL server


M
Masud

xampp\phpMyAdmin/config.inc

Find-

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


I
IAM_AL_X

Also beware that "setup" (i.e. localhost/phpmyadmin/setup) has an error in the way it handles the "no password" option. 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.


I think they're two different directives; see docs.phpmyadmin.net/en/latest/… and docs.phpmyadmin.net/en/latest/…
m
mohit sharma

Try to find $cfg['Servers'][$i]['password'] = ''; in config file located wamp/scripts/config.inc.php

Then set the password to your mysql password and refresh PhpmyAdmin


p
pradeep joshi

i also faced this problem,

i found password field was blank in config file of phpmyadmin. i put that password which i filled in database settings. now it is working fine


N
NevetsKuro

Sometimes the config is not always the problem.

Try checking the MySql config. If yuh have changed the port no. on mysql make the similar changes to PHP config php.ini. Find and replace the necessary changes.