A few words of thanks would be greatly appreciated.

PhpMyAdmin - Access denied for user root@localhost

In PHP programming language there is an open source tool called PhpMyAdmin that handles the administration of MySQL. Access can be denied when access to MySQL is attempted through the root user. Root requires insertion of a password and once that is wrongly entered or is not provided, this issue arises. This can be configured with the help of the PHP tool. The rights of the root user can also be reset at the same time.


Beginners may face problems accessing MySql by the root. This happens when it requires you to enter a password and the user has either entered the wrong one or has not provided one at all. This can be easily configured using the following steps:

  • Step 1: Open MySql.
  • Step 2: Through phpMyAdmin/librarires, you should edit config.inc.php.

    • Where $cfg['PmaAbsoluteUri'] = ''; is displayed, alter the command to $cfg['PmaAbsoluteUri'] = 'localhost/phpmyadmin/';

  • Step 3: Concerning the server commands, change $cfg['Servers'][$i]['host'] = 'localhost'; to $cfg['Servers'][$i]['host'] = 'Localhost';

  • Step 4: To enter root user's new password, find the command $cfg['Servers'][$i]['password'] = ''; and enter it in the field provided.
    • For example: $cfg['Servers'][$i]['password'] = 'type your password here';
  • Step 5: Reboot MySql

To reset the rights of the root user

To be able to reset the root rights, you should enter the following commands:

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost  IDENTIFIED BY ' your current password ' WITH GRANT   

Insert the host and password

This section will allow to insert the host's name and user account by default and set them up with the correct password, as allocated to them in the php.ini folder. To do so, use the code below:

  • Default host for mysql_connect() (doesn't apply in safe mode):
    • mysqli.default_host ='localhost'    
  • Default user for mysql_connect() (doesn't apply in safe mode):
    • mysqli.default_user ='root'    
  • Default password for mysqli_connect() (doesn't apply in safe mode):
    • Note: It is generally a bad idea to store passwords in this file as any user with PHP access can view it

    • mysqli.default_pw =' your current password '</ital>

Image: © Unsplash


A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « PhpMyAdmin - Access denied for user root@localhost », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).