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

I have a php script on my server which is called by my client app to log some information into a remote mysql server. The scripts works fine, but occasionally (only occasionally) the script fails to connect.

I set up the scripts to send me error mails whenever a connection is failed, and I got the following error from mysql_error():

Unknown MySQL server host '[myDBhostaddress]' (2)

Where [myDBhostaddress] is, of course, a correct address of my db host. For the majority of time the script works, thus I don't think the address or log in credential is wrong.

I try to reproduce the problem but no luck. I can log in to my mysql server from my local machine, my server machine. Connecting from command line works, test php scripts works, and manually invoking those scripts which sent me error mails also work!

I'm pretty confused by this problem now, as I don't know how I can deal with it. I don't even know the cause of the problem. Would it be the mysql server overloaded? Would it be an attack by intruders?

And if it helps, my php scripts are living in Amazon's EC2, and mysql server in Amazon's RDS.

share|improve this question
    
Do you connect to a hostname or an IP address? –  Frands Hansen Aug 21 '12 at 20:36
    
@FrandsHansen I am connecting using the host name, so something like *.rds.amazon.com –  Xavier_Ex Aug 21 '12 at 20:38

1 Answer 1

up vote 0 down vote accepted

You should try to use an IP address of the DB server instead of its FQDN, this error is a temporary DNS resolving problem. If you use an IP the DB client simply does not need to perform a DNS lookup.

share|improve this answer
    
That is a good point! I have never thought it might cause problems. I also (even more) occasionally get the "Lost connection to MySQL server at 'reading initial communication packet', system error: 110" error, but at a more seldom rate than the unknown host thing. Would this also be caused by the DNS resolving issue? –  Xavier_Ex Aug 21 '12 at 20:42
    
Just to point out, this also would require you to make code changes if/when you move the db to a different machine. It's a tradeoff. I would investigate WHY it is that your resolution is not working. If it's because of some other network issue (which from your comment doesn't sound out of the question) then that should be addressed instead of blaming DNS resolution and ripping it out. –  squillman Aug 21 '12 at 20:55
    
Darn! When I was trying to fix the issue by using ip address instead of the host name, I figured that Amazon doesn't provide you an IP address for their RDS server... Only an endpoint, which is the host name... –  Xavier_Ex Aug 21 '12 at 21:02
    
@squillman Thanks for pointing that out, since the IP fix isn't possible now, I need to check for other issues. However the problem is I cannot reproduce the problem, so it seems only temporary. And temporary problems are the hardest to fix because no body knows the cause :\ –  Xavier_Ex Aug 21 '12 at 21:05

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.