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: make the mariadb client print warnings during an import

Mariadb
~/tips/tip-mariadb-show-warnings-flag

mariadb --show-warnings -u root -p shop < data.sql

Surfaces truncated and altered values that a quiet import would hide.

An import that finishes without errors can still have changed your data. Out of range numbers get clipped and long strings cut when strict mode is off, and the only trace is a warning.

Ask the client to print them as they happen:

mariadb --show-warnings -u root -p shop < data.sql

After each statement that raised one, you get a line with a code and a message, for example:

Warning (Code 1264): Out of range value for column 'a' at row 1

I’d redirect the output to a file for large imports, then search it. No output at all is what you want to see.

Inside an interactive session the shortcut is \W to turn warnings on and \w to turn them off, or type SHOW WARNINGS; right after a statement. That last one only remembers the most recent statement, so run it before doing anything else.

Check SELECT @@sql_mode; as well. With a strict mode such as STRICT_TRANS_TABLES, many of these problems become errors that stop the import, which is often the better outcome. Dump files sometimes set their own mode at the top, so the setting you checked beforehand may not be the one in force during the load.

Warnings tell you after the fact. The row has already been stored in its altered form, so for important data, load into a scratch database first, read the warnings, fix the source and only then import for real.

Further reading: mariadb command line client, SHOW WARNINGS

More Mariadb tips ALTER TABLE t ADD COLUMN z INT INVISIBLE; CREATE SEQUENCE s START WITH 100 INCREMENT BY 10; CREATE OR REPLACE TABLE scratch ( mariadb --init-command="SET SESSION sql_mode='STRICT_ALL_TABLES'" mydb mariadb-admin -u root -p extended-status --relative --sleep=10 \ All Mariadb tips (15) All topics

Link