[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7536
  • Last Modified:

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

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 http://www.apachefriends.org/en/xampp-windows.html).  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 www.apachefriends.org/en/xampp-windows.html 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.
  • 2
1 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
mathbiolAuthor Commented:
I have reposted the question along with an author comment on the general programming site (see
http://www.experts-exchange.com/Programming/Q_21421657.html), hoping to get a quicker response.  I will close this one out here shortly.
mathbiolAuthor Commented:
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.  

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now