I don't think that is a firewall matter as far as i can connect to the sql server using
telnet localhost 3306
I also can connect using the mysql client (mysql -u root -p)
It seems that php has the problem?
I also use chroot jail (/chroot/users) is where apache runs.