skip to content

Search

Syspirit
EN

MariaDB

MariaDB Database: MySQL compatible and open source!

Databases
Published on

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/Debiansudo apt install mariadb-server mariadb-client
🎩 CentOS/RHELsudo yum install mariadb-server mariadb
🍎 macOS (Homebrew)brew install mariadb
🐳 Dockerdocker run -d mariadb:11
🏢 Official versionmariadb.org/download

⚙️ Basic Configuration

📌 Action🧠 Command
▶️ Start MariaDBsudo systemctl start mariadb
🔄 Enable at bootsudo systemctl enable mariadb
🔒 Secure installationsudo mysql_secure_installation
🔗 Connect as rootsudo mysql -u root -p
📊 View statussudo systemctl status mariadb
🚪 Exit mysqlquit; (or exit;)

🗄️ Database Management

📌 Action🧠 Command
📋 List databasesSHOW DATABASES;
🆕 Create a databaseCREATE DATABASE myapp;
🗑️ Delete a databaseDROP DATABASE myapp;
🔗 Use a databaseUSE myapp;
📊 Current databaseSELECT DATABASE();
💾 Database sizesSELECT table_schema, SUM(data_length) FROM information_schema.tables GROUP BY table_schema;

👥 User Management

📌 Action🧠 Command
📋 List usersSELECT User, Host FROM mysql.user;
👤 Create a userCREATE USER 'john'@'localhost' IDENTIFIED BY 'password';
🔐 Change passwordALTER USER 'john'@'localhost' IDENTIFIED BY 'new_password';
🗑️ Delete a userDROP USER 'john'@'localhost';
👤 Remote userCREATE USER 'john'@'%' IDENTIFIED BY 'password';
🔄 Reload privilegesFLUSH PRIVILEGES;

🔒 Permissions Management

📌 Action🧠 Command
🔑 All rights on a databaseGRANT ALL PRIVILEGES ON myapp.* TO 'john'@'localhost';
📖 Read-only rightsGRANT SELECT ON myapp.* TO 'john'@'localhost';
✏️ Read/write rightsGRANT SELECT, INSERT, UPDATE, DELETE ON myapp.* TO 'john'@'localhost';
👑 Administrator rightsGRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
🚫 Revoke rightsREVOKE ALL PRIVILEGES ON myapp.* FROM 'john'@'localhost';
📋 View permissionsSHOW GRANTS FOR 'john'@'localhost';

💾 Backup and Restore

📌 Action🧠 Command
💾 Backup a databasemysqldump -u root -p myapp > backup.sql
💾 Backup all databasesmysqldump -u root -p --all-databases > all_backup.sql
💾 Backup structure onlymysqldump -u root -p --no-data myapp > structure.sql
💾 Backup data onlymysqldump -u root -p --no-create-info myapp > data.sql
📥 Restore a databasemysql -u root -p myapp < backup.sql
📥 Restore from scriptmysql -u root -p < all_backup.sql

🔍 Monitoring and Debug

📌 Action🧠 Command
📈 View processesSHOW PROCESSLIST;
💾 System variablesSHOW VARIABLES;
📊 Server statusSHOW STATUS;
🔧 Kill a queryKILL QUERY process_id;
📊 Database sizesSELECT 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 versionSELECT VERSION();