Access denied for user ‘root’@’localhost’

Posted by & filed under MYSQL, PHP.

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) “

Access denied for user ‘root’@'localhost’
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()); 


Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts

If you want any of my script need to be customized according to your business requirement,

Please feel free to contact me [at] muni2explore[at]

Note: But it will be charged based on your customization requirement

Get Updates, Scripts & Other Useful Resources to your Email

Join 10,000+ Happy Subscribers on feedburner. Click to Subscribe (We don't send spam)
Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.

%d bloggers like this:

Get Instant Script Download Access!