WP get stuck with a query on MySQL when the site is resumed

I had an issue similar to this with two separate machines (db and web). Calls from web server to the db server were taking an extraordinary amount of time and it turned out to be that MySQL was trying to do IP resolution on each call to it, causing a DNS lookup. Because the db server was internal and had no connection to the outside world, the lookup would eventually timeout.

I resolved the problem by adding the skip-name-resolve directive in the my.conf file on the db server.