Apache: mysql_connect(): Access denied for user 'root'

Posted on 2005-05-11
Last Modified: 2013-12-13
Hi.  On Windows 2000, I installed MySQL and tested it successfully.  I  installed Apache and PHP.  I am using Apache "An own side publishing" (see  In other words I plan to build my pilot site on my own computer without trying to make it accessible to the world yet.

I am using the book "PHP & MySQL for dummies" (was loaned to me).  I successfully ran the first test in the book, which has the phpinfo() command.  That worked.

What I'm stuck on is the next test, where I try to make a mysql connection.  The instructions in say to do it like this:
which I did, but got this error message when I tried to view the file in my browser:

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

(I am happy working without a password at this point.)

In case you need it, here is the whole source file:
<title>Test MySQL</title>
<!-- mysql_up.php -->

/* mysql_connect($host,$user,$password); */
$sql="show status";
$result = mysql_query($sql);
if ($result == 0)
   echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
elseif (mysql_num_rows($result) == 0)
   echo("<b>Query executed successfully!</b>");
<!-- Table that displays the results -->
<table border="1">
    for ($i = 0; $i < mysql_num_rows($result); $i++) {
      $row_array = mysql_fetch_row($result);
      for ($j = 0; $j < mysql_num_fields($result);  $j++) {
        echo("<TD>" . $row_array[$j] . "</td>");
<?php } ?>

Thank you.
Question by:mathbiol
    LVL 51

    Accepted Solution

    check with your mysql client program if you can connect to your database as user root
    if root really has no password then you probably need to use mysql_connect() with an empty password
    LVL 3

    Author Comment

    I have reposted the question along with an author comment on the general programming site (see, hoping to get a quicker response.  I will close this one out here shortly.
    LVL 3

    Author Comment

    Thank you ahoffmann.  Your comment eventually helped me realize that I had to deinstall the first version of MySQL that I had installed before installing XAMPP.  I also had to stop MySQL and start it again.

    The book makes a big point about installing MySQL first, but for the XAMPP approach, this is evidently not appropriate, because it includes MySQL.  When I originally installed MySQL, I set a password.  So when I tried to connect to MySQL with XAMPP, it was confused.  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now