MySQL Reverse DNS lookups are often the cause of long delay and slow MySQL performance when running certain SQL queries. This problem can be fixed by disabling MySQL reverse dns lookup. This is a server-side MySQL configuration, and you need to restart MySQL server to reflect the result.
For older installations, execute below command:
nano /etc/mysql/my.cnf
For newer installations, execute below command:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Locate the mysqld block, and add below line:
skip-name-resolve
After the change, it should look like in the below image:
Save the file and restart MySQL server.
service mysql restart