Results 1 to 3 of 3

Thread: [RESOLVED] Help with MYSQL connection error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Resolved [RESOLVED] Help with MYSQL connection error

    Hi All,

    I have just started using XAMPP for my PHP and MYSQL work. I tried to connect to the MYSQL database with the code below.


    Code:
    <html>
    
    <head>
    
    <title>How to connect to a database</title>
    
    </head>
    
    <body>
    
    <?php
    $username = "root";
    $password = "root";
    $hostname = "localhost"; 
    
    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password) 
      or die("Unable to connect to MySQL");
    echo "Connected to MySQL<br>";
    ?>
    
      
    </body>
    </html>


    But I got the following error.

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\mywork\connect.php on line 18
    Unable to connect to MySQL

    My questions are as follows:


    1) What is wrong with my log in details? Where did the 'YES' password come from?

    2) If anyone has used XAMPP before, could you let me know how or where to change the username and password?

    3) How do I connect to a database succesfully?

    I will greatly appreciate your help please.

    Menre

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Help with MYSQL connection error

    1. the password is not yes. MySQL is telling you that you ARE using a password, but that it's incorrect.

    2. I've never used xampp, but on a default MySQL install the password for the root account is blank. I just looked up the documentation for xampp's installs and it seems that they install MySQL with the default password. so, changing your password to an empty string should fix everything. if you want to change this, you will need to issue a command in the MySQL console, and then also update your phpMyAdmin install (in config.inc.php) to reflect the new root password. should be something like so:

    C:\xampp\mysql\bin\mysqladmin -u root password mynewpassword

    3. the code you have there will correctly connect to MySQL.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Resolved Re: Help with MYSQL connection error

    Hello,

    Thanks a million for your help. You saved me from many hours of unecessary worry. I followed your posting and left the password blank. After deleting the word root for the password, I saved and tested my work again. I tell you what, amazingly, I saw a message on the screen 'Connected to MySQL'.

    Once again, thank you.

    Menre

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width