Link to home
Create AccountLog in
Avatar of lee_murphy
lee_murphy

asked on

ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

Hi,

There are heaps of issues on here with people not being able to connect to their mysql server on localhost, most issues seem to be due to the service not being started.  However mine's a little different.

Running mysql 5.0 & Windows Server 2003

When I go into the mysql\5.0\bin and type mysql and hit return I get the following error:

ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

However, when I open the MySQL Administrator and choose Tools \ MySQL Command Line Client it opens \mysql\5.0\bin\mysql.exe and I'm at a mysql prompt and can do what I want in there.

I'm not sure what attributes are run when it's run from within the MySQL Administrator but I can connect to the MySQL server externally using ODBC but can't connect locally from my PHP file, which reports

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

Like I said, if I use the same details to remote connect from my PC I get connected no problem.  Any ideas where to start?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Are you running a stand-alone version of MySQL or are you running thru something like WAMP or XAMPP?

Also, MySQL permissions are based on username, password AND connection.  Do you have a user that is allowed to connect thru 'localhost' with a password?  It is Not the same as a remote connection.  Most of the time, I create two connections with the same username and password but one is for 'localhost' and the other is for anyhost '%'.
Avatar of lee_murphy
lee_murphy

ASKER

It's a stand-alone version of MySQL.  The user I'm testing with is the root user, who has permission for localhost, 127.0.0.1 and %.

As I said, it connects no problem when the MySQL Command Prompt is opened via the MySQL Administrator, so the host would be the same surely?
Not necessarily.  The 'mysql' command line program has a lot of options.  http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html   Look at the 'host' and 'protocol' options.
Yeah, so if I can find out what options are used when it's called from them menu with the Administrator that would go a way to figuring out my problem...I think :)
Since you "shouldn't" be using the root user for remote connections, try creating another regular user with 'localhost' permissions and see what happens when you try to login with that.
Yeah, I can connect remotely with the new user.  Although I'm not sure it's user details that's the problem, surely if I type mysql on it's own with no user details it should at least bring me to a mysql prompt? This just gives me the above error, and no prompt.
No, on my machine it gives an Access denied for user 'ODBC'@'localhost'.  You need a valid login for the command line program to connect.
I have valid logins, like I say they can connect remotely, no matter what I put in the command line it always returns the above error
I've also tried something else, I've taken this script:

<?php
$hostname = "www.mysite.ie";
$username = "myUser";
$password = "myPassword";

$dbh = mysql_connect($hostname, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error());

?>

Put it on two servers, one being the local server and one being a remote server, the remote server worked fine and connected, the local server still gets:

Access denied for user 'myUser'@'localhost' (using password: YES)

In the mysql.users table there are three entries for myUser:

%
127.0.0.1
localhost
ASKER CERTIFIED SOLUTION
Avatar of lee_murphy
lee_murphy

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Glad you figured it out.  I would not have guessed a port problem since part of it was working.
I figured it out.