brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mysqlshow lists databases, tables and columns without opening a client

CLI
~/tips/tip-mysql-mysqlshow-overview

mysqlshow

Shows databases, tables or columns from the command line, with optional index and row counts.

Sometimes I only want to know what is in a server: which databases exist, which tables a schema holds. Starting the full client for that feels like opening a toolbox to find a screw. mysqlshow answers it in one line.

mysqlshow
mysqlshow mydb
mysqlshow mydb mytable

With no arguments it lists the databases. With a database name it lists the tables, and with a table name too it lists the columns and their types. It is a command-line front end for the SHOW statements, so you see only what your account has privileges on. Add the usual -u and -p options for credentials.

Two options make it more useful:

  • --keys (-k) shows the table indexes.
  • --count shows the number of rows per table.
mysqlshow --count mydb

The docs warn that the count can be slow for tables that are not MyISAM, which means almost every InnoDB table, so I would not run it casually against a big production schema.

The gotcha is wildcards. If the last argument contains *, ?, % or _, it is treated as a pattern. A table called my_table can therefore print matching table names instead of its columns. The documented fix is an extra % as a final argument:

mysqlshow mydb my_table %

On MariaDB the same tool is installed as mariadb-show.

Further reading: MySQL mysqlshow

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link