Recently my tech team came across a weird problem. It was a MySQL server that was taking forever to serve each query (between 4 to 6 seconds). After taking a deep look, what we found was that the mysql reverse dns lookup was causing the slow that our customer noticed.
How can I turn off MySQL reverse dns lookup?
By turning off mysql rdns lookup you can improve your MYSQL response times dramatically, as we did for our customer.
Disable MySQL reverse dns lookups only take 1 minute. With just a simple line placed inside your MySQL configuration file you can fix this slow mysql response.
Add this to /etc/my.cnf under the [mysqld] configuration block:
# Skip MYSQL Reverse DNS lookup skip-name-resolve
Now restart MySQL to apply changes:
On cPanel servers:
service mysql restart
On CentOS/RHEL plain servers:
service mysqld restart
What changes after I set skip-name-resolve on my.cnf?
skip-name-resolve directive lets mysql avoid dns lookup response when checking for clients connections to the mysql server. This way, your MYSQL server will only use IP addresses, instead of hostnames.
If you choose to use skip-name-resolve, make sure your MYSQL connection privileges are set to allow IPs, and not hosts.
On most systems, for the local MySQL Server you will need to use host=127.0.0.1 for ipv4 and host=::1 for ipv6 networks, instead of the classic “host=localhost”.
That’s all, after you set skip-name-resolve on my.cnf you will notice your mysql queries are really fast, usually less than 0.5 seconds if your application is developed following good programming practices. Remember to always include this simple configuration inside your my.cnf file to turn off mysql reverse dns lookups.