MariaDB is an open source fork of MySQL, developed by the original MySQL creators to guarantee openness and performance.
🤔 Why MariaDB?
MariaDB is for:
- 🆓 100% free - Even for enterprise, no paid license
- 🔄 MySQL replacement - Easy to migrate
- ⚡ Fast - Optimized for websites
- 🛡️ Secure - Built-in encryption
Use it for:
- WordPress, Drupal (classic CMS)
- PHP websites (LAMP stack)
- Replacing MySQL when you want free
- “Standard” web applications
🚀 Installation
| 📌 System | 🧠 Command |
|---|---|
| 🐧 Ubuntu/Debian | sudo apt install mariadb-server mariadb-client |
| 🎩 CentOS/RHEL | sudo yum install mariadb-server mariadb |
| 🍎 macOS (Homebrew) | brew install mariadb |
| 🐳 Docker | docker run -d mariadb:11 |
| 🏢 Official version | mariadb.org/download |
⚙️ Basic Configuration
| 📌 Action | 🧠 Command |
|---|---|
| ▶️ Start MariaDB | sudo systemctl start mariadb |
| 🔄 Enable at boot | sudo systemctl enable mariadb |
| 🔒 Secure installation | sudo mysql_secure_installation |
| 🔗 Connect as root | sudo mysql -u root -p |
| 📊 View status | sudo systemctl status mariadb |
| 🚪 Exit mysql | quit; (or exit;) |
🗄️ Database Management
| 📌 Action | 🧠 Command |
|---|---|
| 📋 List databases | SHOW DATABASES; |
| 🆕 Create a database | CREATE DATABASE myapp; |
| 🗑️ Delete a database | DROP DATABASE myapp; |
| 🔗 Use a database | USE myapp; |
| 📊 Current database | SELECT DATABASE(); |
| 💾 Database sizes | SELECT table_schema, SUM(data_length) FROM information_schema.tables GROUP BY table_schema; |
👥 User Management
| 📌 Action | 🧠 Command |
|---|---|
| 📋 List users | SELECT User, Host FROM mysql.user; |
| 👤 Create a user | CREATE USER 'john'@'localhost' IDENTIFIED BY 'password'; |
| 🔐 Change password | ALTER USER 'john'@'localhost' IDENTIFIED BY 'new_password'; |
| 🗑️ Delete a user | DROP USER 'john'@'localhost'; |
| 👤 Remote user | CREATE USER 'john'@'%' IDENTIFIED BY 'password'; |
| 🔄 Reload privileges | FLUSH PRIVILEGES; |
🔒 Permissions Management
| 📌 Action | 🧠 Command |
|---|---|
| 🔑 All rights on a database | GRANT ALL PRIVILEGES ON myapp.* TO 'john'@'localhost'; |
| 📖 Read-only rights | GRANT SELECT ON myapp.* TO 'john'@'localhost'; |
| ✏️ Read/write rights | GRANT SELECT, INSERT, UPDATE, DELETE ON myapp.* TO 'john'@'localhost'; |
| 👑 Administrator rights | GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION; |
| 🚫 Revoke rights | REVOKE ALL PRIVILEGES ON myapp.* FROM 'john'@'localhost'; |
| 📋 View permissions | SHOW GRANTS FOR 'john'@'localhost'; |
💾 Backup and Restore
| 📌 Action | 🧠 Command |
|---|---|
| 💾 Backup a database | mysqldump -u root -p myapp > backup.sql |
| 💾 Backup all databases | mysqldump -u root -p --all-databases > all_backup.sql |
| 💾 Backup structure only | mysqldump -u root -p --no-data myapp > structure.sql |
| 💾 Backup data only | mysqldump -u root -p --no-create-info myapp > data.sql |
| 📥 Restore a database | mysql -u root -p myapp < backup.sql |
| 📥 Restore from script | mysql -u root -p < all_backup.sql |
🔍 Monitoring and Debug
| 📌 Action | 🧠 Command |
|---|---|
| 📈 View processes | SHOW PROCESSLIST; |
| 💾 System variables | SHOW VARIABLES; |
| 📊 Server status | SHOW STATUS; |
| 🔧 Kill a query | KILL QUERY process_id; |
| 📊 Database sizes | SELECT table_schema, ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS 'DB Size in MB' FROM information_schema.tables GROUP BY table_schema; |
| ⚡ View version | SELECT VERSION(); |