Mysql – Can not connect to the sql database

amazon ec2amazon-web-servicesMySQL

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

Best Answer

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