Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to connect to mysql database on amazon through a php script, but I am shown this error:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111

I have tried and searched places and did the following things:

  • In "/etc/mysql/my.cnf" I commented out the line bind address: 127.0.0.1 to allow the acccess to all.
  • checked /etc/hosts.allow and /etc/hosts.deny and made sure that there are no rules present that may cause

But still no luck. Please suggest any other way.

Thanks, Madhup

share|improve this question

3 Answers 3

up vote 1 down vote accepted

do you connect from php to 127.0.0.1 ?

are you sure you have restarted your mysql after changing the configuration file?

can you connect to mysql using command line:

mysql -uroot -psomePass -h127.0.0.1

do you see on what port mysql listens? can it be it is non-standard port?

netstat -lanp|grep mysqld|grep LISTEN

is it possible that your iptables does not allow connections over loopback? run

iptables -I INPUT -i lo -j ACCEPT
iptables -I OUTPUT -o lo -j ACCEPT
share|improve this answer
    
I have got it working right now. The problem was that mysql was not getting restarted. It failed to restart but today it restarted, any suggestion or idea why it was not restarting or it happens sometimes without any reason. –  Madhup Singh Yadav May 17 '10 at 10:03
    
@madhup corrupted/removed by mistake pidfile comes to my mind as possible excuse for that behavior. –  pQd May 17 '10 at 11:26

Here's a MySQL forum post that should help.

share|improve this answer

how is binding mysql to 127.0.0.1 allowing access to all? if you're connecting from an external server, you'll need to bind mysql to the external IP address, so that you can connect remotely.

you may also wish to add some firewall rules, i.e.

/sbin/iptables -A INPUT -p tcp --dport 3306 -s <php_host_ip> -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 3306 -j DROP

to block access to mysql from any other hosts, even though mysql is supposed to take care of itself, it's better to have two locked doors, than one.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.