Site icon Ninotronix

MariaDB Cheatsheet: A Quick Reference Guide for Database Management

mariadb-commands

mariadb-commands

Basic Commands

CommandDescription
sudo systemctl start mariadbStart MariaDB service
sudo systemctl stop mariadbStop MariaDB service
sudo systemctl restart mariadbRestart MariaDB service
sudo systemctl status mariadbCheck MariaDB service status
sudo mysqlConnect to MariaDB server
exitExit MariaDB server

Database Management

CommandDescription
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

CommandDescription
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

CommandDescription
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

CommandDescription
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
Exit mobile version