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: tee in the mariadb client logs your whole database session to a file

Database
~/tips/tip-database-mariadb-tee-session-log

MariaDB [shop]> tee /tmp/fix-orders.log

Records every query and result of an interactive session in a log file.

For manual fixes in a database, I like having a record of what was typed and what came back. The client has that built in.

MariaDB [shop]> tee /tmp/fix-orders.log
MariaDB [shop]> SELECT count(*) FROM orders WHERE total = 0;
MariaDB [shop]> notee

Between tee and notee, the client appends everything to the file: the prompt with each query, the result tables and the row counts. You still see it all on screen as well. The short form is \T /tmp/fix-orders.log, and you can start with it on from the shell using mariadb --tee=/tmp/fix-orders.log shop.

That file is useful afterwards. You can paste it into a ticket, compare the counts before and after, or work out what went wrong when a fix did more than planned.

Keep in mind where the file lands. The path is on the machine where the client runs, so inside a container it ends up in the container’s filesystem and disappears with it. The log also contains the data you queried, so do not leave it in /tmp on a shared server. The client appends to an existing file and never empties it, so one file can collect several sessions.

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