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: mariadb-check --check-only-changed checks all tables from the command line

Mariadb
~/tips/tip-database-mariadb-check-check-only-changed

mariadb-check -u root -p --all-databases --check-only-changed

Checks every MariaDB table from the shell, optionally only those changed since the last check.

After a power cut or a container that was killed, I would like to know whether any table got damaged, without typing CHECK TABLE a hundred times. MariaDB has a client for that, and it is the same tool that used to be called mysqlcheck.

mariadb-check -u root -p --all-databases --check-only-changed

The docs describe it as a maintenance tool that checks, repairs, analyzes and optimizes many tables at once from the command line. It is basically a command-line interface to the CHECK TABLE, REPAIR TABLE, ANALYZE TABLE and OPTIMIZE TABLE statements. Checking is the default if you give no other action.

With -C / --check-only-changed it only looks at tables that have changed since the last check or that were not closed properly, which keeps the run short. --fast (-F) checks only tables that were not closed properly, and --quick (-q) avoids scanning the rows for wrong links, which the docs call the fastest check. For one database you can name it: mariadb-check -u root -p appdb.

The docs list a few limits to keep in mind:

  • The server has to be running, unlike with myisamchk and aria_chk.
  • It does not work with partitioned tables.
  • Not all options are supported by all storage engines.
  • The options for check, repair, analyze and optimize exclude each other.

I would stick to checking. --repair and --auto-repair exist, and the docs say --auto-repair repairs corrupted tables after all tables have been checked, but I want a fresh backup before something rewrites my tables. So: dump first, check second, repair last and only when needed.

Further reading: MariaDB documentation: mariadb-check

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