|
-
Apr 16th, 2009, 10:48 AM
#1
Thread Starter
Addicted Member
[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
-
Apr 16th, 2009, 03:20 PM
#2
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.
-
Apr 17th, 2009, 03:12 AM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|