Slow MySQL access (from PHP, command-line client)
A really simple issue which has caused me problems once or maybe twice in the past.
Symptoms
When connecting to a MySQL database from either the command-line or from a PHP page, there is an initial delay of a few seconds before the connection is established. There are no reasons for there to be any network latency (i.e. you’re connecting from the same machine as your database server or there is a fast link between the two).
This can manifest itself as PHP pages which connect to a database being really slow to load but HTML / CSS / Javascript files being very fast.
Cause
No reverse DNS entry for the IP address from which you are connecting.
By default, MySQL tries to do a reverse DNS lookup on the IP address of every client connection. If there is no reverse DNS entry for the IP address from which you’re connecting, this will fail. Depending on your DNS server configuration, it might take a few seconds to time out.
Resolution
Arguably, the correct way to fix this issue is to add a reverse DNS entry for your MySQL client host to your DNS server. Ensuring that your DNS is correctly set up is quite important for a few reasons, this being one. However, there are several situations in which it is either not desirable or practical to create the DNS entry. In this case, simply add the following line to your my.ini MySQL configuration on your database server and restart MySQL:
skip-name-resolve
Alternatively, start your MySQL process with the --skip-name-resolve
option.