On a busy server, it’s often hard to keep track of what’s running and when, so from time to time, you may find yourself wondering what MySQL is doing. Luckily, MySQL provides a degree of transparency that makes it relatively easy to peer inside and see what’s up.
On a busy server, it’s often hard to keep track of what’s running and when, so from time to time, you may find yourself wondering what MySQL is doing. Luckily, MySQL provides a degree of transparency that makes it relatively easy to peer inside and see what’s up.
Who and What
One of the most basic questions that you’re likely to ask is, “Who’s connected to MySQL and what are they doing?” Now, you could fall back on classic Unix tools such as netstat to figure out which clients have connections open to TCP port 3306, but that would tell you only which machines are connected — not necessarily who is connected. The best way to track down who’s connected to MySQL is to use MySQL’s own SHOW PROCESSLIST command. Like most of MySQL’s SHOW commands, it produces easy to read tabular output, as shown in Figure One.
Figure One
+——–+——————+———————-+————+————————–+ | Id | User | Host | db | Command | Time | State | Info | +——–+——————+———————-+————+————————–+ | 17 | jzawodn | localhost | NULL | Query | 0 | NULL | show |
In Figure One, you’ll see one “record” for each connected user, detailing who the user is, what they’re doing, and so on. Here’s what the columns mean:
* ID. This is the “thread id” for the given…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: