MariaDB Cheatsheet: A Quick Reference Guide for Database Management
Basic Commands
Command | Description |
---|---|
sudo systemctl start mariadb | Start MariaDB service |
sudo systemctl stop mariadb | Stop MariaDB service |
sudo systemctl restart mariadb | Restart MariaDB service |
sudo systemctl status mariadb | Check MariaDB service status |
sudo mysql | Connect to MariaDB server |
exit | Exit MariaDB server |
Database Management
Command | Description |
---|---|
CREATE DATABASE dbname; | Create a new database |
DROP DATABASE dbname; | Delete a database |
SHOW DATABASES; | Show all databases |
USE dbname; | Select a database to use |
SHOW TABLES; | Show all tables in the selected database |
DESCRIBE tablename; | Show the structure of a table |
ALTER TABLE tablename ADD COLUMN columnname datatype; | Add a column to a table |
Data Management
Command | Description |
---|---|
INSERT INTO tablename (column1, column2, ...) VALUES (value1, value2, ...); | Insert a new row into a table |
UPDATE tablename SET columnname = newvalue WHERE condition; | Update a value in a table |
DELETE FROM tablename WHERE condition; | Delete a row from a table |
SELECT column1, column2, ... FROM tablename WHERE condition ORDER BY columnname ASC/DESC LIMIT numrows; | Select data from a table |
User Management
Command | Description |
---|---|
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; | Create a new user |
DROP USER 'username'@'localhost'; | Delete a user |
GRANT ALL ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'password'; | Grant a user privileges on a database |
FLUSH PRIVILEGES; | Apply changes to user privileges |
Miscellaneous
Command | Description |
---|---|
SHOW PROCESSLIST; | Show all running queries |
SHOW VARIABLES LIKE 'variable_name'; | Show the value of a MariaDB system variable |
SET GLOBAL variable_name = value; | Set the value of a MariaDB system variable |