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: pager less -S in the mariadb client keeps wide database tables readable

Database
~/tips/tip-database-mariadb-pager-less-s

MariaDB [shop]> pager less -S

Sends query output through less without line wrapping, so wide tables stay aligned.

A SELECT * on a table with fifteen columns wraps every row over three lines in the terminal, and the ASCII table turns into noise. The client can pipe its output through a pager.

MariaDB [shop]> pager less -S
PAGER set to 'less -S'
MariaDB [shop]> SELECT * FROM orders;
MariaDB [shop]> nopager

-S tells less to chop long lines instead of wrapping them. The table keeps its shape, and you scroll sideways with the arrow keys. Search with / works like anywhere else in less, which I find handy for long results. Press q to go back to the prompt.

If you always want it, start the client with --pager='less -S' or put pager=less -S in the [mariadb-client] group of your ~/.my.cnf. The pager command also takes other programs, so pager grep -i error filters output, which is a nice trick with SHOW ENGINE INNODB STATUS.

It only applies in interactive mode. With -e or a piped script, the client writes straight to stdout and ignores the pager. Adding -F, as in less -SF, makes less quit on its own when a result fits on one screen, so short results don’t need a q.

Further reading: mariadb command-line client

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link