MySQL and MariaDB are the most popular databases. Here are the most important commands:
Connecting
mysql -u root -pDatabases
SHOW DATABASES; # list the databasesCREATE DATABASE my_db; # create a database
DROP DATABASE my_db; # delete a database
USE my_db; # select a database
Users
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';GRANT ALL ON my_db.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
SHOW GRANTS FOR 'username'@'localhost';
DROP USER 'username'@'localhost';
Tables
SHOW TABLES; # list the tablesDESCRIBE table_name; # table structure
Backup and restore
Backupmysqldump -u root -p my_db > backup.sql
Restore
mysql -u root -p my_db < backup.sql
Useful commands
SHOW PROCESSLIST; # running queriesSHOW STATUS; # server status
EXIT; # exit
Any questions? Write here!