Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7068
  • Last Modified:

Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in

i am getting this strange error, the scenario:
two separate server, apache and mysql

i can connect manually from apacheserver to mysqlserver using mysql command line and list tables etc.

however the php pages on apacheserver do not connect to databases:

i have  all these packages installed:

ii  libapache2-mod-php5               5.2.6.dfsg.1-1+lenny2                server-side, HTML-embedded scripting languag
ii  libapache2-mod-suphp              0.6.2-3                              Apache2 module to run php scripts with the o
ii  libphp-adodb                      5.05-1                               The ADOdb database abstraction layer for PHP
ii  php-benchmark                     1.2.7-2                              Framework to benchmark PHP scripts or functi
ii  php-date                          1.4.7-1                              PHP PEAR module for date and time manipulati
ii  php-db                            1.7.13-2                             PHP PEAR Database Abstraction Layer
ii  php-file                          1.3.0-1                              PHP Pear modules for common file and directo
ii  php-html-template-it              1:1.2.1-2                            PEAR HTML Template IT
ii  php-http                          1.4.0-1                              PHP PEAR module for HTTP related stuff
ii  php-mail                          1.1.14-1                             PHP PEAR module for sending email
ii  php-net-smtp                      1.3.1-1                              PHP PEAR module implementing SMTP protocol
ii  php-net-socket                    1.0.8-2                              PHP PEAR Network Socket Interface module
ii  php-pear                          5.2.6-3                              PEAR - PHP Extension and Application Reposit
ii  php-xml-parser                    1.2.8-1                              PHP PEAR module for parsing XML
ii  php4-common                       6:4.4.4-9+lenny1                     Common files for packages built from the php
ii  php4-pear                         6:4.4.4-9+lenny1                     PHP Extension and Application Repository (tr
ii  php5                              5.2.6-3                              server-side, HTML-embedded scripting languag
ii  php5-adodb                        5.04-3                               Extension optimising ADOdb database abstract
ii  php5-cgi                          5.2.6.dfsg.1-1+lenny2                server-side, HTML-embedded scripting languag
ii  php5-cli                          5.2.6.dfsg.1-1+lenny2                command-line interpreter for the php5 script
ii  php5-common                       5.2.6.dfsg.1-1+lenny2                Common files for packages built from the php
ii  php5-curl                         5.2.6.dfsg.1-1+lenny2                CURL module for php5
ii  php5-dev                          5.2.6-3                              Files for PHP5 module development
ii  php5-gd                           5.2.6.dfsg.1-1+lenny2                GD module for php5
ii  php5-imagick                      2.1.1RC1-1                           ImageMagick module for php5
ii  php5-imap                         5.2.6.dfsg.1-1+lenny2                IMAP module for php5
ii  php5-mcrypt                       5.2.6.dfsg.1-1+lenny2                MCrypt module for php5
ii  php5-mysql                        5.2.6.dfsg.1-1+lenny2                MySQL module for php5
ii  php5-pgsql                        5.2.6.dfsg.1-1+lenny2                PostgreSQL module for php5
ii  php5-pspell                       5.2.6.dfsg.1-1+lenny2                pspell module for php5
ii  php5-suhosin                      0.9.24-1                             advanced protection module for php5
ii  php5-xmlrpc                       5.2.6.dfsg.1-1+lenny2                XML-RPC module for php5
pi  suphp-common                      0.6.2-3                              Common files for mod suphp

simple php pages works which shows php is loaded in apache and is working properly, but why does the php pages not connect to databases though the command line from the server works!

any ideas???
0
krisdigitx
Asked:
krisdigitx
  • 7
  • 6
1 Solution
 
bansidharCommented:
what is the mysql_error() message?
0
 
krisdigitxAuthor Commented:
Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /home/dir/public_html/test.php on line 11
Unable to select database
0
 
bansidharCommented:
There was a bug in mysql, but I think this is fixed now, anyhow try using the name of the server to connect to the mysql server instead of IP.
But before that try a restart of the httpd server. Also check if you are using the correct port to connect to the mysql server. These are the items I have faced with this error.
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
krisdigitxAuthor Commented:
the test page uses the ip of the server, tried with the domain name as well, it gives that the same error, it uses the default port 3306 also.
0
 
bansidharCommented:
check if your mysql is bound to just ip 127.0.0.1. Try making MySQL listen on any address. Not just 127.0.0.1
but try a httpd restart before this.
0
 
krisdigitxAuthor Commented:
mysql server is a remote server and is listening on all interfaces..

0.0.0.0:3306

making it localhost will not work as the apache webserver is a separate server.
0
 
bansidharCommented:
error code 111 is "Connection refused". are you using the same username/password you used from command line? Cannot think of some other thing now :(
0
 
krisdigitxAuthor Commented:
its the same login/password........
0
 
bansidharCommented:
last resort I can think of, try a restart of the web server, and/or try a reboot of the machine running web server.
0
 
krisdigitxAuthor Commented:
reboot did not work..
0
 
bansidharCommented:
almost hands up. but can you post the mysql part of dbinfo() command here?
0
 
krisdigitxAuthor Commented:
fixed, it was the iptables, flushed the rules and it worked.
0
 
bansidharCommented:
great you fixed it. Check my comment
error code 111 is "Connection refused"
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now