PHP can't connect to MySQL

CaldwellYSR

Member
So I'm learning php, I've learned all the basic stuff about php and mysql and now I'm about to start learning how to make them interact with one another. The php code is:

Code:
<?php 
[INDENT]$connection = mysql_connect("localhost", "root", "my_password");[/INDENT]
?>

When I try to load this page I keep getting this error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES)

I know my password is correct because I can log into mysql using terminal. (and I assume that's what using password: YES means). So why am I getting this error?
 

nafirici

New Member
in mysql, run the following to ensure root has access from localhost.
show grants for 'root'@'localhost';

if you don't have permissions:
grant all on *.* to 'root'@'localhost' identified by 'whateveryourpasswordis';

if you do have permissions, check to make sure your password is correct. The using password yes, simply means you entered a password, not that you entered the correct one.
 
Top