If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost' (10061)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-28-10, 08:50
R_14_14 R_14_14 is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
Question ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost' (10061)

Hi, I can't seem to connect to MySQL via PHP. I get the following error message when I try:

----------------------------------------------------------------------------------
Warning: mysql_connect(): [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mysqlconnect.php on line 3 Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mysqlconnect.php on line 3 Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mysqlconnect.php on line 3
----------------------------------------------------------------------------------

I am running windows 7 with Apache 2.2, PHP 5.3 and MySQL server 5.1. In task manager, ApacheMonitor is running under processes and Apache is running under services. MySQL is listed under services, but is stopped. When I try to access MySQL via the command line I get the following error message:

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

So it would seem I have installed/configured Apache/MySQL wrong. Could anyone please tell me what I should check for? e.g. is there a setting in one of the .ini files that I should change?

Thanks!

P.S. when I first installed MySQL I could access it via the command line fine, but I still couldn't connect via PHP. Not being able to access it via command line is a recent development.
Reply With Quote
  #2 (permalink)  
Old 09-28-10, 09:44
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
MySQL must be started. It is a service running in the background and is waiting listening for any incoming connections.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 09-28-10, 13:10
R_14_14 R_14_14 is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
OK I've now got MySQL running and can access it from command line, however I still get the first error message when trying to connect via PHP. Any ideas what could be causing this?

My PHP script is as follows:
Code:
<?php

$link = mysql_connect  ('localhost', 'root', 'PASSWORD');

if (!$link) {
    die('Could not connect: ' . mysql_error());
}
else {
    print 'successful';
}
mysql_close($link);

?>
The only thing I wasn't sure about was the username 'root', when installing MySQL it never asked me for a username. Could this or something else in the PHP script be the issue? or is there something wrong with the way I have set up PHP/MySQL/Apache?
Reply With Quote
  #4 (permalink)  
Old 09-28-10, 13:44
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Hi,

the first thing I would do it verify the username and the password. If no password exists just ignore that parameter i.e. mysql_connect("localhost", "root");

The best way to verify this is to use command line mysql program passing in the username and password if one exists and verify that these are correct. Then using the same parameters hostname, username and password add them to the mysql_connect call.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #5 (permalink)  
Old 09-29-10, 07:13
R_14_14 R_14_14 is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
OK thanks for the suggestions so far. No luck though. So far I have done the following:

I have run phpinfo(); there is indeed a MySQL section. Belowis some of the output that phpinfo gives, I know no-one is eager to trawl through it looking for the problem, but if anyone has an idea please do look at it, it would be a massive help!

MySQL is indeed listening at port 3306; although I am just trying to connect to MySQL locally, from the same computer that has the database on it (eventually I just want to test a website that I am designing), so I dont know, does this still apply?

Also I have tried to connect with my firewall completely turned off, just in case, but still get same error message.

I have also run the following from the command line:

CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'passwrd'; and changed the user to 'testuser' and password to 'passwrd' etc. in my PHP script to make absolutely sure I am using the right user, host and password - still get same error message.

I've been trying to get this working for days now, any help is much appreciated!


PHP Version 5.3.3

System Windows NT RLJ-LAPTOP 6.1 build 7600 (Unknow Windows version Home Premium Edition) i586
Build Date Jul 21 2010 20:00:47
Compiler MSVC6 (Visual C++ 6.0)
Architecture x86
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--disable-isapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=D:\php-sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static"
Server API Apache 2.0 Handler
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File C:\Program Files (x86)\PHP\php.ini
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,TS,VC6
PHP Extension Build API20090626,TS,VC6
Debug Build no
Thread Safety enabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support enabled
Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, compress.bzip2, https, ftps, phar
Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tls
Registered Stream Filters convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*, bzip2.*

Configuration
apache2handler

Apache Version Apache/2.2.16 (Win32) PHP/5.3.3
Apache API Version 20051115
Server Administrator [.....]
Hostname:Port 127.0.0.1:0
Max Requests Per Child: 0 - Keep Alive: on - Max Per Connection: 100
Timeouts Connection: 300 - Keep-Alive: 5
Virtual Server No
Server Root C:/Program Files (x86)/Apache Software Foundation/Apache2.2
Loaded Modules core mod_win32 mpm_winnt http_core mod_so mod_actions mod_alias mod_asis mod_auth_basic mod_authn_default mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_dir mod_env mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_setenvif mod_php5

Directive Local Value Master Value
engine 1 1
last_modified 0 0
xbithack 0 0

Apache Environment
Variable Value
HTTP_HOST localhost
HTTP_USER_AGENT Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGE en-gb,en;q=0.5
HTTP_ACCEPT_ENCODING gzip,deflate
HTTP_ACCEPT_CHARSET ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_KEEP_ALIVE 115
HTTP_CONNECTION keep-alive
PATH C:\Program Files (x86)\PHP\;C:\Windows\system32;C:\Windows;C:\Windo ws\System32\Wbem;C:\Windows\System32\WindowsPowerS hell\v1.0\;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;
SystemRoot C:\Windows
COMSPEC C:\Windows\system32\cmd.exe
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;. MSC
WINDIR C:\Windows
SERVER_SIGNATURE no value
SERVER_SOFTWARE Apache/2.2.16 (Win32) PHP/5.3.3
SERVER_NAME localhost
SERVER_ADDR 127.0.0.1
SERVER_PORT 80
REMOTE_ADDR 127.0.0.1
DOCUMENT_ROOT C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs
SERVER_ADMIN .......................
SCRIPT_FILENAME C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/PHPinfo.php
REMOTE_PORT 49417
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING no value
REQUEST_URI /phpinfo.php
SCRIPT_NAME /phpinfo.php

Core
PHP Version 5.3.3

Directive Local Value Master Value
allow_call_time_pass_reference Off Off
allow_url_fopen On On
allow_url_include Off Off
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions no value no value
display_errors On On
display_startup_errors Off Off
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl Off Off
error_append_string no value no value
error_log C:\Windows\temp\php-errors.log C:\Windows\temp\php-errors.log
error_prepend_string no value no value
error_reporting 22527 22527
exit_on_timeout Off Off
expose_php On On
extension_dir C:\Program Files (x86)\PHP\ext C:\Program Files (x86)\PHP\ext
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors Off Off
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort Off Off
implicit_flush Off Off
include_path .;C:\php5\pear .;C:\php5\pear
log_errors On On
log_errors_max_len 1024 1024
magic_quotes_gpc Off Off
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.add_x_header On On
mail.force_extra_parameters no value no value
mail.log no value no value
max_execution_time 30 30
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 60 60
memory_limit 128M 128M
open_basedir no value no value
output_buffering 4096 4096
output_handler no value no value
post_max_size 8M 8M
precision 14 14
realpath_cache_size 16K 16K
realpath_cache_ttl 120 120
register_argc_argv Off Off
register_globals Off Off
register_long_arrays Off Off
report_memleaks On On
report_zend_debug On On
request_order GP GP
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path no value no value
serialize_precision 100 100
short_open_tag Off Off
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 2M 2M
upload_tmp_dir C:\Windows\Temp C:\Windows\Temp
user_dir no value no value
user_ini.cache_ttl 300 300
user_ini.filename .user.ini .user.ini
variables_order GPCS GPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.enable_gc On On
Reply With Quote
  #6 (permalink)  
Old 09-29-10, 07:14
R_14_14 R_14_14 is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version mysqlnd 5.0.7-dev - 091210 - $Revision: 300533 $

Directive Local Value Master Value
mysql.allow_local_infile On On
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off

mysqli
MysqlI Support enabled
Client API library version mysqlnd 5.0.7-dev - 091210 - $Revision: 300533 $
Active Persistent Links 0
Inactive Persistent Links 0
Active Links 0

Directive Local Value Master Value
mysqli.allow_local_infile On On
mysqli.allow_persistent On On
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.max_persistent Unlimited Unlimited
mysqli.reconnect Off Off

mysqlnd
mysqlnd enabled
Version mysqlnd 5.0.7-dev - 091210 - $Revision: 300533 $
Compression supported
SSL not supported
Command buffer size 4096
Read buffer size 32768
Read timeout 31536000
Collecting statistics Yes
Collecting memory statistics No

Additional Modules
Module Name


Environment
Variable Value
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Windows\system32\config\systemprofile\AppData\R oaming
CommonProgramFiles C:\Program Files (x86)\Common Files
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
CommonProgramW6432 C:\Program Files\Common Files
COMPUTERNAME RLJ-LAPTOP
ComSpec C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK NO
LOCALAPPDATA C:\Windows\system32\config\systemprofile\AppData\L ocal
NUMBER_OF_PROCESSORS 2
OS Windows_NT
Path C:\Program Files (x86)\PHP\;C:\Windows\system32;C:\Windows;C:\Windo ws\System32\Wbem;C:\Windows\System32\WindowsPowerS hell\v1.0\;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;. MSC
PHPRC C:\Program Files (x86)\PHP\
PROCESSOR_ARCHITECTURE x86
PROCESSOR_ARCHITEW6432 AMD64
PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 10, GenuineIntel
PROCESSOR_LEVEL 6
PROCESSOR_REVISION 170a
ProgramData C:\ProgramData
ProgramFiles C:\Program Files (x86)
ProgramFiles(x86) C:\Program Files (x86)
ProgramW6432 C:\Program Files
PSModulePath C:\Windows\system32\WindowsPowerShell\v1.0\Modules \
PUBLIC C:\Users\Public
SystemDrive C:
SystemRoot C:\Windows
TEMP C:\Windows\TEMP
TMP C:\Windows\TEMP
USERDOMAIN WORKGROUP
USERNAME RLJ-LAPTOP$
USERPROFILE C:\Windows\system32\config\systemprofile
windir C:\Windows
AP_PARENT_PID 1732

PHP Variables
Variable Value
_SERVER["HTTP_HOST"] localhost
_SERVER["HTTP_USER_AGENT"] Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
_SERVER["HTTP_ACCEPT"] text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
_SERVER["HTTP_ACCEPT_LANGUAGE"] en-gb,en;q=0.5
_SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate
_SERVER["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.7
_SERVER["HTTP_KEEP_ALIVE"] 115
_SERVER["HTTP_CONNECTION"] keep-alive
_SERVER["PATH"] C:\Program Files (x86)\PHP\;C:\Windows\system32;C:\Windows;C:\Windo ws\System32\Wbem;C:\Windows\System32\WindowsPowerS hell\v1.0\;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;
_SERVER["SystemRoot"] C:\Windows
_SERVER["COMSPEC"] C:\Windows\system32\cmd.exe
_SERVER["PATHEXT"] .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;. MSC
_SERVER["WINDIR"] C:\Windows
_SERVER["SERVER_SIGNATURE"] no value
_SERVER["SERVER_SOFTWARE"] Apache/2.2.16 (Win32) PHP/5.3.3
_SERVER["SERVER_NAME"] localhost
_SERVER["SERVER_ADDR"] 127.0.0.1
_SERVER["SERVER_PORT"] 80
_SERVER["REMOTE_ADDR"] 127.0.0.1
_SERVER["DOCUMENT_ROOT"] C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs
_SERVER["SERVER_ADMIN"] ..........
_SERVER["SCRIPT_FILENAME"] C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/PHPinfo.php
_SERVER["REMOTE_PORT"] 49417
_SERVER["GATEWAY_INTERFACE"] CGI/1.1
_SERVER["SERVER_PROTOCOL"] HTTP/1.1
_SERVER["REQUEST_METHOD"] GET
_SERVER["QUERY_STRING"] no value
_SERVER["REQUEST_URI"] /phpinfo.php
_SERVER["SCRIPT_NAME"] /phpinfo.php
_SERVER["PHP_SELF"] /phpinfo.php
_SERVER["REQUEST_TIME"] 1285755604
Reply With Quote
  #7 (permalink)  
Old 09-29-10, 08:27
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
From the same host have you tried connecting from the command line executable mysql to verify the username and password?

If this is not possible then have a look at running php script.php to see if this works? script.php is the code that you provided attempting to connect to the database.

Another thing, do you have a firewall setup on your host? Could this be blocking attempts to talk with port 3306?
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #8 (permalink)  
Old 09-29-10, 12:16
R_14_14 R_14_14 is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
Hi, thanks for all the suggestions. In the end I solved the problem by uninstalling everything and re-installing via WAMP. much simpler.

still no idea really what caused it tho.
Reply With Quote
  #9 (permalink)  
Old 09-29-10, 13:13
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
I've never really been a fan of Windows for running databases. Glad you got it working!!
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

Tags
apache, connect, mysql connection error, mysql installation, mysql_connect

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On