Fix Access denied for user 'root'@'localhost' for phpMyAdmin
Asked Answered
C

18

86

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?

Crotch answered 20/10, 2013 at 20:18 Comment(4)
privilages are host specificPhotoconduction
Edit your %windir%\system32\drivers\etc\hosts file and add/uncomment 127.0.0.1 localhost in itSyne
Sometimes login problems with phpMyAdmin can be fixed by clearing all of their cookies.Oppress
@xyz, your comment solved my issue. I was stuck and wasted my half day.Spandex
B
114

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';
Bilious answered 24/2, 2014 at 9:7 Comment(6)
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.Ridgeling
Here I have got a suggestion to make this solution more smooth. After that last line of code you can also add <code>$cfg['Servers'][$i]['AllowNoPassword'] = true;</code>Bilious
Short and efficient answer. Thank you!Larcenous
Not exist anything like $cfg['Servers'][$i]['password'] in this config file ...Birefringence
Good to know: For XAMPP on W7, the file is /xampp/phpMyAdmin/config.inc.phpPaisano
This worked for me. I didn't want any passwords for my local setup and so I messed up my phpadmin. My password was admin` so command for me was $cfg['Servers'][$i]['password'] = 'admin';Terrorism
A
30

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'] = '';
Algerian answered 31/10, 2014 at 15:45 Comment(2)
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.Kagu
Yes you need to synchronize the updates on all the files because they depend on each other.Algerian
W
21

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.

Whore answered 5/2, 2014 at 5:28 Comment(0)
B
16

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';
Bimanous answered 15/6, 2016 at 7:21 Comment(1)
this is working when, stop first the running Apache and MySql, then to the steps above.Boardinghouse
B
7

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

Butterbur answered 11/3, 2016 at 13:50 Comment(0)
K
6

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!

Klug answered 17/9, 2014 at 10:23 Comment(1)
Most APT And EXACT SolutionAbaxial
M
6

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

Mercaptide answered 5/4, 2015 at 20:24 Comment(0)
T
4

@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
Tyne answered 21/10, 2013 at 9:27 Comment(1)
Adding ::1 localhost was the perfect solution in my case. Thanks a ton!Strop
T
4

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

Tinea answered 16/2, 2015 at 13:0 Comment(0)
C
3

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

Catenane answered 1/8, 2016 at 15:54 Comment(0)
H
3

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


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



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



5. Save the changes and open your browser and paste
http://localhost/phpmyadmin/index.php
to navigate to phpMyAdmin
Hundley answered 4/11, 2020 at 20:0 Comment(0)
K
2

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.

Kiwi answered 21/2, 2015 at 14:8 Comment(0)
P
2

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
Pecten answered 15/3, 2015 at 7:34 Comment(0)
C
2

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.

Cf answered 20/10, 2015 at 16:41 Comment(1)
I think they're two different directives; see docs.phpmyadmin.net/en/latest/… and docs.phpmyadmin.net/en/latest/…Freed
A
2

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

Ailin answered 25/12, 2015 at 18:46 Comment(0)
E
2

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

Ebberta answered 6/8, 2016 at 9:38 Comment(0)
B
0

For ubuntu users, you can try this

stop MYSQL

sudo service mysql stop

Restart lamp/xamp

sudo /opt/lampp/lampp restart
Bakemeier answered 23/2, 2023 at 9:51 Comment(0)
Y
-1

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.

Yulan answered 16/10, 2020 at 6:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.