Connection refused

I was recently put in-charge of overseeing the database server migration — from Oracle to MySQL.

We had all worked really hard, making sure we stick to the schedule as prescribed. Until two days before the final migration, I realised that the web server couldn’t connect to the database server.

“Connection refused” it said.

“It must be the firewall!” I thought. Our client had co-located a web server, a backup web server and their old Oracle database, and we were not managing the firewall, so it was easy to pin responsibility on the much-maligned firewall. Then I looked at the firewall — it was allowing incoming/outgoing connections on the MySQL port, no issue. Hmmm.

So I wrote a script to test for connectivity:

$link = mysql_connect('w.x.y.z:3306:/tmp/mysql.sock', 'wayne-devel', ...);

if (!$link) {
die('Could not connect: ' . mysql_error());

echo 'Connected successfully';

There was no return value, not even the “Could not connect” message. So it was the weirdest thing.

It turned out, in ascending order of heartache:

1. the firewall on the database server was blocking incoming mysql connections
2. the firewall on the web server was blocking outgoing mysql connections
3. PHP was not compiled with mysql support on the web server

ARGH. Well. Better now then later I guess.

#linux, #mysql, #php