tips
15 tips Mariadb
One command, setting or habit at a time about Mariadb: what it does, the line to copy and a caveat or two.
Queries and tables 5
-
Hides a column from SELECT * and from inserts that do not name it.
ALTER TABLE t ADD COLUMN z INT INVISIBLE; -
Creates a sequence object that hands out numbers, usable as a column default.
CREATE SEQUENCE s START WITH 100 INCREMENT BY 10; -
Creates a table, replacing it if it already exists, so reruns of a script do not fail.
CREATE OR REPLACE TABLE scratch ( -
Reveals how a slow query is executing without waiting for it to finish.
SHOW FULL PROCESSLIST; -
Lets you query what the data looked like at an earlier moment.
CREATE TABLE prices (
Admin and checks 4
-
Turns ever growing server counters into per interval numbers.
mariadb-admin -u root -p extended-status --relative --sleep=10 \ -
Blocks logins for a user while keeping its password and grants.
ALTER USER 'app'@'localhost' ACCOUNT LOCK; -
Shows which settings are picked up from all the option files together.
my_print_defaults --mysqld -
Checks every MariaDB table from the shell, optionally only those changed since the last check.
mariadb-check -u root -p --all-databases --check-only-changed
SQL shells 4
-
Runs one SQL statement automatically after the client connects, and again after a reconnect.
mariadb --init-command="SET SESSION sql_mode='STRICT_ALL_TABLES'" mydb -
Surfaces truncated and altered values that a quiet import would hide.
mariadb --show-warnings -u root -p shop < data.sql -
Makes the MariaDB client print wide query results vertically, one column per line.
mariadb --auto-vertical-output -u root -p appdb -
Runs one query and prints plain tab-separated rows without borders or a header line.
mariadb -B -N -e "SELECT id, email FROM users WHERE active" appdb
Backups and dumps 2
-
Dumps a MariaDB database but keeps only the structure of the tables you name.
mariadb-dump --single-transaction \ -
Dumps only the table rows that match a SQL condition instead of the whole table.
mariadb-dump --single-transaction --where="created_at >= '2026-01-01'" appdb orders > orders-2026.sql
Nothing in this filter yet.