Problem: Mysql access denied error for user root@localhost when using in XAMPP server (windows) even when credentials are correct.
Solution: Actually the problem is not in code, the issue is that by-default mysql in xampp allowed passwordless authentication in mysql, so we have to disable that and it will work as normal.
Go to XAMPP control panel then open and edit my.ini (mysql config file):
You have to uncomment a statement in below section:
Note: Before uncomment, set the mysql root password from phpmyadmin user setting option:
Line 19 # password = your_password
Uncomment Line 19,
save file and restart mysql service.
And edit config.inc.php file in the phpmyadmin directory:
And replace the below line:
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['password'] = 'your_password';
“your_password” can be anything you like.