Site icon SmartTutorials.net

Access denied for user ‘root’@’localhost’

Are you PHP/MySql programmer may be in your programmer life accidentily you came across following error :

 
“Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘root’@’localhost’ (using password: YES) in C:\xampp\htdocs\daytrader\login.php on line 4
Access denied for user ‘root’@’localhost’ (using password: YES) “


when you access your database using “root” as username, so you clearly open lot of security holes. Please avoid “root” as username when you accessing database in the mysql_connect() function.

mysql_connect(“localhost”, “root”, “”) or die(mysql_error()); 

Here is the simple solution to solve above problem :

So create new user to the particular database or table using following SQL query 

GRANT ALL ON login.* TO ‘muni‘@’localhost‘;

                Where login –  Database name 
                          muni –  User Name
                          Localhost – Server Name.

Now access your database using username (muni), You had just created

mysql_connect(“localhost”, “muni”, “”) or die(mysql_error()); 


.

Exit mobile version