If you are having an issue with a slow MySQL connection to a remote database then perhaps the following can help.
Essentially my website was taking 7-8 seconds to load and the Apache logs weren’t giving me much to go on. Using a website page test tool such as http://www.webpagetest.org I could see that the site itself was performing well but there was a 7 second server wait time.
This lead my on to the assumption that the MySQL connection was causing the issue. To test, I simply created a new database locally and updated the config files. What do you know…the website loads instantly. This confirmed my assumption.
So I set about figuring out why the MySQL connection was so slow even though the remote server was within the same network. The fix is very simple:
Edit the hosts file on the remote MySQL server:
vim /etc/hosts
Add in the following line:
xxx.xxx.xxx.xxx original.host.com original
* xxx being the IP address
The original host being the server you are connecting from. Go back and check your website hopefully everything is back to full speed.
The main reason for adding the entry to the hosts file is due to not having reverse DNS set up. Once the entry has been added manually this will do the lookup manually rather than querying the DNS.
More useful information can be found here: http://etwiki.cpanel.net/twiki/bin/view/11_32/WHMDocs/SetupRemoteMySQL
Is the original.host.com the actual server host domain or the website domain on the webserver?
I added the actual server domain name and that doesn’t seem to make a difference. Plus, why the word original at the end. I presume thats for the server name?
Thanks for the tip.
Hi,
Add the IP of the website and the website domain. The web server you are connecting from may not have a valid domain name. ‘Original’ is the alias name for original.host.com.
Hope this helps.
Matt
the subdomain you are seeing can be fireblade if you are using one.. So, it will now say “xxx.xxx.x.xxx fireblade.host.com fireblade” .. Fireblade in the end is your server alias.
Thanks Joan.