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

PhpMysqlPhpmyadminWamp

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

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

Solution 2 - Php

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

Solution 3 - Php

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.

Solution 4 - Php

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

Solution 5 - Php

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

Solution 6 - Php

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

And suddenly it worked!

Solution 7 - Php

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

Solution 8 - Php

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

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

Solution 9 - Php

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

Solution 10 - Php

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

Solution 11 - Php

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

Solution 12 - Php

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.

Solution 13 - Php

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.

Solution 14 - Php

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

Solution 15 - Php

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

Solution 16 - Php

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


  1. Open the XAMPP control panel
  2. Then select the Explorer Button on the right

    https://i.stack.imgur.com/aErWS.png" height="300">
  3. Then it will be navigated to the location where the configurations are and you have to
    go in side the phpMyAdmin folder
    and then right click on the highlighted folder and choose edit option on any text editor

    https://i.stack.imgur.com/glLvJ.png" height="300">

  4. Then edit only the following rounded section as of your MySQL server username and password
    If your MySQL server username is root and
    If your MySQL server password is root, keep as of the image

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

    https://i.stack.imgur.com/tzWQy.png" height="500" >

  5. Save the changes and open your browser and paste
    http://localhost/phpmyadmin/index.php
    to navigate to phpMyAdmin

Solution 17 - Php

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukeView Question on Stackoverflow
Solution 1 - PhpNikhil GView Answer on Stackoverflow
Solution 2 - PhpEzra A.MosomiView Answer on Stackoverflow
Solution 3 - PhpSyed Nazri bin Wan IkhsanView Answer on Stackoverflow
Solution 4 - Phpshubham balyanView Answer on Stackoverflow
Solution 5 - PhpsimerView Answer on Stackoverflow
Solution 6 - PhpHazem ElraffieeView Answer on Stackoverflow
Solution 7 - PhpAndBecaPineView Answer on Stackoverflow
Solution 8 - PhpRiggsFollyView Answer on Stackoverflow
Solution 9 - PhpHenry DisozaView Answer on Stackoverflow
Solution 10 - PhpnyxeeView Answer on Stackoverflow
Solution 11 - PhpMuhammad AqeelView Answer on Stackoverflow
Solution 12 - PhpMasudView Answer on Stackoverflow
Solution 13 - PhpIAM_AL_XView Answer on Stackoverflow
Solution 14 - Phpmohit sharmaView Answer on Stackoverflow
Solution 15 - Phppradeep joshiView Answer on Stackoverflow
Solution 16 - PhpNiroshan RatnayakeView Answer on Stackoverflow
Solution 17 - PhpNevetsKuroView Answer on Stackoverflow