LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

mytop

displays MySQL server activity in real-time, similar to top for processes

TLDR

Monitor MySQL queries
$ mytop
copy
Connect to specific database
$ mytop -u [user] -p [password] -d [database]
copy
Connect to remote server
$ mytop -h [hostname] -u [user] -p [password]
copy
Slow query mode (threshold in seconds)
$ mytop -s [5]
copy
Show idle connections
$ mytop -i
copy
Specify refresh interval in seconds
$ mytop --delay [3]
copy
Batch mode (run once and exit)
$ mytop --batch
copy
Connect via socket
$ mytop -S [/var/run/mysqld/mysqld.sock]
copy

SYNOPSIS

mytop [-u user] [-p pass] [-h host] [-d database] [options]

DESCRIPTION

mytop displays MySQL server activity in real-time, similar to top for processes. It shows running queries, connections, and server statistics.
The display includes query threads with their states, execution times, and SQL text. Long-running queries stand out for attention.
Server statistics show queries per second, slow queries, threads connected, and cache hit rates. These metrics help identify performance issues.
Slow query mode filters display to queries exceeding a time threshold. This focuses attention on problematic operations.
The kill command terminates runaway queries. Combined with filtering, it helps manage query overload situations.
Connection to remote servers enables monitoring multiple databases from one location.

PARAMETERS

-u USER

MySQL username.
-p PASS
MySQL password.
-h HOST
MySQL server hostname.
-d DB
Default database.
-P PORT
MySQL port.
-s SECONDS
Slow query threshold.
-i
Show idle connections.
--delay SECONDS
Refresh interval.
--color
Use ANSI color.
-S SOCKET
MySQL socket path.
--batch
Batch mode (run once, no screen clearing).
--nocolor
Disable ANSI color output.

KEY COMMANDS

q

Quit.
k
Kill a query/thread.
f
Toggle full query display.
s
Change sort column.
r
Reverse sort order.
p
Pause display.
?
Help.

CAVEATS

Requires MySQL PROCESS privilege. Some features need SUPER privilege. Not actively maintained -- consider alternatives like innotop. May not support all MariaDB features. Configuration can also be read from ~/.mytop file.

HISTORY

mytop was written by Jeremy Zawodny around 2000 when he worked at Yahoo. It became a standard tool for MySQL administrators, filling the gap for real-time server monitoring before such features were built into management tools.

SEE ALSO

mysql(1), mysqladmin(1)

Copied to clipboard
Kai