Mysql – show variables command constantly running on user

connectionsMySQL

I have a bit of an odd problem. I have a number of application user accounts. One account per application rather than one account per user.

I have one application that seems to be hammering the systems resources. CPU usage is at 99% for MySQL from this single user. If I kill the application then usage for the server goes back down to about 20%.

This user account appears to be continuously running the "show variables" command… as far as I can tell, there is absolutely no reference in the application code to "show variables"… though I'm not sure even that should slow down the machine that much… there are also a handful of queries that appear multiple times in the connections list.

So I have two questions/problems:

  1. Is there any reason the "show variables" command would be running constantly like this? Any other sql commands that would cause "show variables" to fire?

AND

  1. Why would I be seeing so many queries getting duplicated for this user? If I have it running from a single PC, that PC generates somewhere around 30-50 connections and many of them are for the same query. So is it running the same query multiple times when it does this?

I'm trying to pinpoint the source of these oddities, so if anyone can point me in some general direction I'd appreciate it.

Best Answer

For home-grown monitoring, you can do several things.

I like the slowlog for finding which queries are resource hogs; it also provides some info to jumpstart figuring out what to do with them. A manual SHOW PROCESSLIST is good if you can catch someone in the act.

Cacti, Nagios, RRD, and several others will assist in continual monitoring of dozens of things. Some are useful; most are rather useless. They are likely to repeatedly do SHOW GLOBAL STATUS. (But, as I have said, that should not be too invasive.)

Simply knowing if the computer is up or not is also important.

If you are using Replication, there are a number of other things to check on. SHOW SLAVE STATUS and its Seconds_behind_master is perhaps the most important.