27

I am unable to connect to my MySQL in xampp I have this error:

MySQL said: Documentation

#1045 - Access denied for user 'root'@'localhost' (using password: NO) mysqli_real_connect(): (HY000/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.

CONFIG.INC.PHP file

<?php
/*
* This is needed for cookie based authentication to encrypt password in
* cookie
*/
$cfg['blowfish_secret'] = 'xampp'; /* YOU SHOULD CHANGE THIS FOR A MORE SECURE COOKIE AUTH! */

/*
* Servers configuration
*/
$i = 0;

/*
* First server
*/
$i++;

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

/* Bind to the localhost ipv4 address and tcp */
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['connect_type'] = 'tcp';

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = '';

/* Advanced phpMyAdmin features */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';

/*
 * End of servers configuration
 */

?>
Ryan M
  • 18,333
  • 31
  • 67
  • 74
guzuer
  • 661
  • 1
  • 6
  • 8

17 Answers17

38

found a solution, in my config file I just changed

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

to

$cfg['Servers'][$i]['auth_type'] = 'HTTP';
guzuer
  • 661
  • 1
  • 6
  • 8
18
/* Authentication type and info */
$cfg['Servers'][$i]['password'] = '';<----your password

or

/* User for advanced features */

$cfg['Servers'][$i]['controluser'] = 'pma';

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

to

/* User for advanced features */

$cfg['Servers'][$i]['controluser'] = 'your user';

$cfg['Servers'][$i]['controlpass'] = 'your password';
haihui
  • 1,075
  • 1
  • 18
  • 25
user9117601
  • 189
  • 1
  • 2
11

You may have set different passwords for user 'root' or have been changed your password. I had the same error as:

mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES)

and I found that my root password for PHPMyAdmin is not the same on both 'mysql' and 'phpmyadmin' databases, so I updated my password for 'phpmyadmin' database same as 'mysql' database as follow:

sudo gedit /etc/phpmyadmin/config-db.php

and update the fields

$dbuser='root';

$dbpass='myNewPassword'; <-- update your new password here
Dharman
  • 30,962
  • 25
  • 85
  • 135
Farhikhteh
  • 111
  • 1
  • 5
  • The answer for my problem is to fix privilege granted user information instead of 'root' as @Farhikhteh told – melic Aug 26 '19 at 17:29
  • This solved my issue! for some strange reason the username and password set by default was not overwritten on installation, going to the config-db.php file led me to my issue! You saved me ! – Julian Silvestri Jan 19 '20 at 00:07
9

Change the value of

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

in your ~/xampp/phpMyAdmin/config.inc.php

Here my username is groot and password is groot.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Jendorski Labs
  • 447
  • 2
  • 9
  • 20
7

It happened with me before: go to path for windows

C:\xampp\phpMyAdmin\

go to path for linux:

/etc/phpmyadmin/

found file name is :
config.inc.php open file
change this:

['password'] = ''

to:

['password'] = 'root'

this default
It might be any password if you changed it from the control panel

CodeView
  • 498
  • 3
  • 14
4

Edit the file xampp/mysql/bin/my.ini

Add

skip-grant-tables

under [mysqld]

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • 1
    Its very dangerous: "When MySQL is started with this parameter, it completely avoids checking its grant tables upon connection and upon query. This means anyone can log in from anywhere, and do anything on the database." http://code.openark.org/blog/mysql/dangers-of-skip-grant-tables – szatti1489 May 16 '18 at 13:43
  • later you grant that using mysql query and then turn of skip-grants a quick workaround – Develop4Life May 19 '18 at 13:25
  • Downvote: it's a bad idea to do that. You should reset the root password (search stackoverflow, there's tons of posts on that) or create an appropriate user, grant te appropriate permissions and configure you config.inc.php – Tomas Gonzalez Aug 09 '18 at 14:34
4

You need to modify the config-db.php and set your password to the password you gave to the user root, or else if he has no password leave as this ''.

  • 1
    Please use the code formatting for e.g. adding config-db.php in code formatting as `config-db.php`. Do the same thing with value such as `'root'` and `''`. Also it will be very helpful if you could copy paste the part of file, along with location. Make sure, while pasting, you remove your private information such as credentials. – Ayush Vatsyayan Oct 03 '18 at 13:12
4

Follow these steps- 1.go to config.inc.php file and find - $cfg['Servers'][$i]['auth_type']

2.change the value of $cfg['Servers'][$i]['auth_type'] to 'cookie' or 'http'.

3.find $cfg['Servers'][$i]['AllowNoPassword'] and change it's value to true.

Now whenever you want to login, enter root as your username,skip the password and go ahead pressing the submit button..

Note- if you choose authentication type as cookie then whenever you will close the browser and reopen it ,again you have to login.

  • I have set this but at time of login I am fetching this error "Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin." – Bhavin Thummar Jan 24 '21 at 15:55
  • @BhavinThummar is it working when you are using incognito mode?? – Nakshtra Pradhan Feb 27 '21 at 14:51
  • 1
    Weird that this one is not the accepted answer, it is the most simpler and logical. With this setup (though I prefer `AllowNoPassword` to `false`) you will get prompted by the native phpMyAdmin login form. With this method, it becomes just matter of changing the `auth_type` to `cookie` . Obviously, from command prompt, you will use `mysqladmin -u root password` to set your own new secure password – Robert Aug 11 '21 at 07:00
3
$cfg['Servers'][$i]['auth_type'] = 'HTTP';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '1234';

This solves my problem too. It just logs in automatically.

2

This is the Different Solution, Check if your Services are running correctly, if WAMP icon showing orange color, and 2 out of 3 services are running it's showing, then this solution will work . Root cause:

If in your system mysql was there, later you installed WAMP then again one MYSQL will install as WAMP package, default port for MYSQL is 3306 , So in both mysql the port will be 3306, which is a port conflict, So just change the port it will work fine. Steps to change the Port.

  1. Right click the WAMP icon.
  2. Chose Tool
  3. Change the port in Port used by MySql Section
Rajanikanta Pradhan
  • 580
  • 1
  • 8
  • 12
2

If you are using macbookpro and getting this error on XAMPP then you also need to change the permission of file config.inc.php. Sorry I was first time user of xampp on macbook pro and was not knowing its directory structure and other details so adding this answer for first time users.

From XAMPP interface click to 'go to Terminal' and from there use below commands

       root@debian: cd /opt/lampp/phpmyadmin

inside this directory you will find the config.inc.php Now use chmod 777 config.inc.php, please note that you need to make it writable you can use equivalent code instead of 777. I used 777 for me.

       root@debian: chmod 777 config.inc.php

Now open the file from explorer or network drive to any editor make the below changes -

  1. search for 'Authentication type' in file, you will find it in comment

  2. below this comment you will find

     $cfg['Servers'][$i]['auth_type'] = 'config';
     $cfg['Servers'][$i]['user'] = 'root';
     $cfg['Servers'][$i]['password'] = 'here_you_need_to_type_your_root_password';
    
  3. now it still didnot work for me after this step, it was complaining about config file permission so I had to revert back the permission back to -rw-r--r-

       root@debian: chmod 644 config.inc.php
    

and then it worked fine.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Brainwash
  • 188
  • 2
  • 10
1

In case none of the aforementioned solutions works for you, then simply do the under changes. Change this

$cfg['Servers'][$i]['host'] = '127.0.0.1';

to

$cfg['Servers'][$i]['host'] = 'localhost';

and

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

to

$cfg['Servers'][$I]['auth_type'] ='cookies';

It works in my situation, possibly works on your situation also.

1

Go got XAMPP->mysql->bin->my.ini

open the file with an editor and add 'skip-grant-tables' after mysql.

Shamal Sabah
  • 229
  • 2
  • 7
0

Just do what the message is asking for, create the user pma@localhost in the phpMyAdmin panel with no password

0

When you install the WAMPP in your machine by default the password of PhpMyAdmin is blank. so put root in user Section and left blank of password field. hope it works.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Arun Prajapati
  • 283
  • 2
  • 6
0

Check /etc/phpmyadmin/config-db.php file

  1. Go to terminal
  2. run vi /etc/phpmyadmin/config-db.php
  3. check the information
  4. Hit Ctrl + X
  5. Try login to phpmyadmin again through the web using the information from the config file.
A. Kiyoshi
  • 61
  • 1
  • 13
0

Please run and re reconfigure your phpmyadmin

sudo dpkg-reconfigure phpmyadmin

kishan maru
  • 31
  • 1
  • 3
  • 8