Jump to content

PHP can't connect to MySQL 5


Fmdpa

Recommended Posts

I’m having such a hard time getting MySQL to work. I decided installed WAMP today because I thought it would be easier to work with the preconfigured installation. It is much easier than manually installing the components, BTW. I figured out how to add/change the password (phpMyAdmin), but I can’t connect to MySQL. My username is the default “root” and the password is “admin”. Here’s what I used to attempt a connection to MySQL.

<?php$con = mysql_connect("localhost","root","admin");if (!$con) {	die('Couldn\'t connect:' . mysql_error());	}?>

The error was this: “Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp\www\newdb.php on line 3Couldn't connect:Access denied for user 'root'@'localhost' (using password: YES) ”I tried using the same code above, except changing “mysql” to “mysqli”.

<?php$con = mysqli_connect("localhost","root","admin");if (!$con) {	die('Couldn\'t connect:' . mysqli_error());	}	?>

This is the error I got:“ Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp\www\newdb.php on line 3Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\wamp\www\newdb.php on line 6Couldn't connect: ”Do you have any suggestions? I am willing to reinstall WAMP if you know how that would fix it.

Link to comment
Share on other sites

It is much easier than manually installing the components, BTW.
That's true. It's very easy to set up something that doesn't work. As someone wiser than myself once said, for every problem there is a solution that is simple, elegant, and wrong.The error is telling you that the username and password for MySQL are not correct. This is not the username and password for phpMyAdmin, it's a MySQL user. You can either create a new user for MySQL using the command line (although you'll still need to log in to do that), or if you don't know what it is you can check in phpMyAdmin's config file and see which username and password it's using to connect to MySQL.
Link to comment
Share on other sites

The error is telling you that the username and password for MySQL are not correct. This is not the username and password for phpMyAdmin, it's a MySQL user.
But the phpMyAdmin documentation says this:
Many people have difficulty understanding the concept of user management with regards to phpMyAdmin. When a user logs in to phpMyAdmin, that username and password are passed directly to MySQL. phpMyAdmin does no account management on its own (other than allowing one to manipulate the MySQL user account information); all users must be valid MySQL users.
Does that mean that only when you are managing databases with PMA does MySQL accept the password I specified in the "Privileges" tab? Do I need to use the MySQL command line to modify the account info? If so, where is there a good tutorial on how to do this? Do I need to use the windows cmd prompt, or the mysql command line (mysql/mysql5.x/bin/mysql)?
Link to comment
Share on other sites

That's right, when I was installing it I remember being able to do user management a couple ways, although phpMyAdmin still needed a root MySQL login. I'm able to add a new user with PMA and then use it to log into the MySQL command line and run queries. Make sure you're using the correct password, create a new user if you want to. That error message should only happen if the user name and password are not correct.

Link to comment
Share on other sites

I just reinstalled WAMP. I was trying to access the MySQL command-line. I opened windows cmd prompt, entered the path "wamp\bin\mysql\mysql5.x\bin\"; That did not work. So I looked around some more. I clicked on the WAMP icon on the system tray, and selected MySQL>MySQL Console. That did it. It asked for the password. I just hit enter, since there was no password. It logged me in and asked for a command. After creating, dropping several DBs and tables just to test it, I satisfactorily closed it and went over the NP++. I created a new doc with the connection code mentioned above, except I left out the password argument. No errors showed! I entered a query to create a new db. I went over the PMA, and it was listed with the other databases! It works, and I'm very excited!!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...