MariaDB Community

Reference cheatsheet

Frequently-needed SQL, system variables, and CLI tools

CLI tools

CommandUse
mariadbClient (mysql still aliased)
mariadb-dumpLogical backup
mariabackupPhysical hot backup
mariadb-adminAdmin (status, flush, shutdown)
mariadb-upgradeRun after every version bump
mariadb-checkVerify / repair tables
mariadb-secure-installationRun once after fresh install

Inspection SQL

SELECT VERSION(), @@version_comment;
SHOW DATABASES;
SHOW TABLES;
SHOW CREATE TABLE orders;
DESC orders;
SHOW INDEXES FROM orders;
SHOW FULL PROCESSLIST;
SHOW VARIABLES LIKE 'innodb%';
SELECT user, host FROM mysql.user;
SHOW GRANTS FOR 'alice'@'%';

Table sizes:

SELECT table_schema, table_name,
       ROUND(data_length/1024/1024,2)  AS data_mb,
       ROUND(index_length/1024/1024,2) AS idx_mb,
       table_rows
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql','information_schema','performance_schema','sys')
ORDER BY data_length + index_length DESC;

User templates

-- Read-only (for BI / agents)
CREATE USER 'readonly'@'%' IDENTIFIED BY 'strong-pass';
GRANT SELECT, SHOW VIEW ON appdb.* TO 'readonly'@'%';

-- App account
CREATE USER 'app'@'10.%' IDENTIFIED BY 'strong-pass';
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'app'@'10.%';

-- Backup account (10.5+)
CREATE USER 'backup'@'localhost' IDENTIFIED BY 'strong-pass';
GRANT RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT, SHOW VIEW, EVENT, TRIGGER ON *.* TO 'backup'@'localhost';
GRANT BACKUP_ADMIN ON *.* TO 'backup'@'localhost';
FLUSH PRIVILEGES;

Connection URIs

mysql://USER:PASS@HOST:3306/DB?charset=utf8mb4

# Python: mysql+pymysql://app:pass@host:3306/db?charset=utf8mb4
# Node:   mysql://app:pass@host:3306/db?charset=utf8mb4
# Go:     app:pass@tcp(host:3306)/db?charset=utf8mb4&parseTime=true&loc=Local
# JDBC:   jdbc:mariadb://host:3306/db?useUnicode=true&characterEncoding=utf8

Default port: 3306. Wire protocol compatible with MySQL.

External

On this page