My server has been really sluggish recently. I checked with htop, and it's often stalling on disk reads. I checked with atop and iotop, and it looks like mysql is demanding a lot of diskIO. I haven't investigated streamlining mysql yet, but I was wondering if it's possible to tell what program is accessing it. (I have several programs running, such as Nextcloud, tt-rss, ejabberd, nagios.)

$ pgrep -a mysql
3422 /bin/bash /usr/bin/mysqld_safe
3585 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/arm-linux-gnueabihf/mariadb18/plugin --user=mysql --skip-log-error --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306

How can I tell which program is accessing mysql?

1 Answer 1


Use the command lsof -n | grep mysql. Probably a .sock file somewhere in /var.

  • 1
    Eep! That returned 3969 lines. It contains things like /lib/arm-linux-gnueabihf/, /usr/lib/arm-linux-gnueabihf/, /var/lib/mysql/, and /var/run/mysqld/mysqld.sock, many of them duplicates, but I'm uncertain how to troubleshoot further.
    – Sparhawk
    Commented Jul 3, 2017 at 12:32
  • Try ' | grep -iv \/lib | sort -u'
    – user2497
    Commented Jul 3, 2017 at 12:35
  • If you want network connections to mysql, use 'netstat -an | grep mysql'
    – user2497
    Commented Jul 3, 2017 at 12:37
  • What do your mysql logs say?
    – user2497
    Commented Jul 3, 2017 at 12:38
  • Still 865 lines. I'm not sure how to parse lsof output, it looks like the number of columns is inconsistent? Anyway, | awk '{print $10}' | sort | uniq is a bit clearer, but it's not like I see anything that relates to process names in the output. I'm not sure that it's necessarily network connections either.
    – Sparhawk
    Commented Jul 3, 2017 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .