Home / Alt manpages / mytop(1)

  • mytop(1)
  • User command
  • linux

Watch MariaDB Activity Safely with mytop

By the end of this guide you will be able to connect mytop to a MariaDB server, read its live activity display, and take a non-interactive snapshot without putting a database password in the process list. The examples match the MariaDB 10.11 client shipped here as mariadb-client 1:10.11.14-0ubuntu0.24.04.1.

Before you start

Allow roughly 10 minutes if the database account already exists. You need the mytop command, Perl DBI with a MariaDB or MySQL driver, and the terminal support used by interactive mode. More importantly, the database account must be allowed to read SHOW PROCESSLIST and SHOW STATUS. You do not need root on Linux, and you should not run the monitor with sudo just to make a database login work.

Have these values ready:

  • the MariaDB host, port or Unix socket;
  • a monitoring username with the required read access; and
  • the database name, if you want to set one for the connection.

Checkpoint

This guide observes the server. It does not change MariaDB configuration or install a monitoring account.

1. Confirm the local client and server endpoint

Check the installed command before troubleshooting authentication. The local manpage is deliberately brief, so the most useful version detail comes from the installed script itself:

command -v mytop
dpkg-query -W -f='${Package} ${Version}\n' mariadb-client
mytop --host=127.0.0.1 --port=3306 --user=monitor --prompt --nocolor

Replace monitor and the address with real values. The last command is an actual connection attempt. It asks for the password without exposing it as a command-line argument. On a healthy connection, an interactive screen refreshes every five seconds by default. If the server is absent, the command stops with a connection error instead of showing useful data.

The installed 10.11 script accepts --host, --port, --user, --prompt and --nocolor. It also accepts short forms such as -h, -P and -u. The manpage and command both use localhost, port 3306, and user root as defaults. A default is not a recommendation: choose a dedicated account with only the visibility you need.

2. Choose TCP or a Unix socket

Use TCP when you are monitoring another host or want the endpoint to be unambiguous:

mytop --host=DB_HOST --port=3306 --user=monitor --prompt --nocolor

Use a socket when the client and server are on the same machine and you know its path:

mytop --socket=/run/mysqld/mysqld.sock --user=monitor --prompt --nocolor

For the socket form, replace the placeholder with an existing socket path. A socket takes precedence over host and port. If the named path is not a socket, this version falls back to the host and port rather than treating the bad path as a successful local connection. That fallback can distract you: check the path and the resulting error carefully.

Checkpoint

Run one of the commands above and confirm that the first line identifies the expected MariaDB host and server version. If it fails, fix reachability or credentials before changing display options.

3. Read the live display

The upper section summarises server state: uptime, total queries, average and current queries per second, slow queries, query mix, threads, handlers, temporary tables, and traffic. The lower section lists visible threads with an ID, user, host, database, idle time, command and query or state. Long query text needs a wide terminal; a narrow window makes the monitor harder to read, not the server healthier.

Interactive mode refreshes every five seconds. Change that interval at startup when a slower view is less distracting:

mytop --host=DB_HOST --user=monitor --prompt --delay=10 --nocolor

Press ? for the in-program help and q to quit. Useful controls include i to show or hide idle threads, o to reverse the sort order, h to filter by host, u to filter by user, d to filter by database, f to inspect a full query for a thread, and H to toggle the summary header.

Some keys change server state. In particular, k can kill a thread and r sends FLUSH STATUS to reset status counters. Treat both as operational actions, not harmless display shortcuts. Do not use them while investigating a production incident unless you have separately agreed that action.

4. Make credentials and defaults less error-prone

Do not use --pass=SECRET in a shared shell or script. The installed documentation warns that a command-line password is visible to other users through process inspection. Prefer the prompt:

mytop --host=DB_HOST --port=3306 --user=monitor --prompt

For repeat use, put non-secret defaults in ~/.mytop. One setting per line is accepted, with optional whitespace around the equals sign:

host=DB_HOST
port=3306
user=monitor
delay=5
header=1
color=0
idle=1

Keep this file private if it contains a password. A safer version leaves pass empty and keeps --prompt on the command line. The client also reads the [client] and [mytop] groups from the normal MariaDB option files through my_print_defaults, then reads ~/.mytop. Command-line arguments are applied last, so they override those defaults.

Do not mistake ~/.mytop for a MariaDB server configuration file. It controls this invocation of the monitor. To undo the example defaults, remove the lines you added or move the file aside, then start mytop with explicit options. No elevated privilege is required for either action.

5. Capture a one-off snapshot

Use batch mode when you need output for a log, ticket or quick comparison rather than a full-screen interface:

mytop --host=DB_HOST --port=3306 --user=monitor --prompt --batch --nocolor > mytop-snapshot.txt

--batch runs one cycle, does not clear the screen, and does not limit output to the terminal height. The redirection creates or replaces mytop-snapshot.txt in the current directory, so check the filename before pressing Enter. To preserve an existing file, choose a new timestamped name or use shell redirection that you have reviewed first. The snapshot may include query text and usernames; treat it as operational data and protect or remove it according to your normal policy.

Verify that the command succeeded and that the file is non-empty:

test -s mytop-snapshot.txt && sed -n '1,12p' mytop-snapshot.txt

If authentication fails, the shell redirection may still leave an empty file. Remove that empty artefact with rm -- mytop-snapshot.txt only after checking the path. The command does not alter MariaDB, but deleting the wrong path is still irreversible.

Common failure modes

  • Cannot connect to the socket: the default is the local host and port, and the socket path may differ between distributions. Try the documented socket explicitly or use TCP with the real port.
  • Access denied or empty process data: verify the monitoring account's grants. A Linux administrator account and a MariaDB account are separate identities.
  • Unknown option: this is not a generic top clone. For example, this installed command does not provide a general --help or --version option; press ? after connecting or read mytop(1).
  • Colours or interactive input fail: add --nocolor and use --batch for redirected output. Batch mode avoids terminal key handling.
  • Numbers look compact: the display abbreviates large values by default. Use --long when full digits are more useful than a compact view.

Done means

  • mytop connects to the intended MariaDB host and account.
  • You can distinguish summary counters from the live thread list.
  • Your password is not present in the command line or an unnecessarily broad config file.
  • You know that k and r change server state and leave them alone unless authorised.
  • A batch snapshot, when needed, is verified and handled as sensitive operational output.