How To Install MariaDB on Debian Based Linux

In this article,  we will go through how to install MariaDB on a Debian based Linux machine.  MariaDB is a community-developed, open-source relational database management system (RDBMS) that is highly compatible with MySQL. It was forked from MySQL in 2009 due to concerns about Oracle’s acquisition of MySQL. MariaDB aims to remain free and open-source under the GNU General Public License (GPL). Many of the original developers of MySQL lead the development of MariaDB.   Like MySQL, MariaDB serves as a reliable and scalable database for a wide range of applications. This includes web applications, enterprise-level applications, and mobile apps, providing structured data storage and retrieval.  MariaDB is a popular choice for the backend of dynamic websites and web applications. Its speed, reliability, and ability to handle high traffic make it suitable for managing user data, product catalogs, and transactional information for e-commerce platforms and content management systems (CMS) like WordPress.  MariaDB, especially with its ColumnStore storage engine, can be used for data warehousing and analytical purposes. Its columnar architecture and parallel processing capabilities enable efficient querying and analysis of large datasets.  In many cases, MariaDB can function as a direct replacement for MySQL without requiring significant code changes. This allows users to benefit from MariaDB’s enhancements and additional features.   

Step 1: Update Your System

Open your terminal and run:

sudo apt update

sudo apt upgrade -y

This ensures all packages are current.

Step 2: Install MariaDB Server

Use the default package manager to install MariaDB:

sudo apt install mariadb-server mariadb-client -y

This installs both the server and client components.

Step 3: Check That MariaDB Installed Correctly

Confirm the version:

mariadb –version

Output should show something like:
mariadb 10.x.x

Step 4: Enable and Start the MariaDB Service

Ensure the database service is running and enabled on boot:

sudo systemctl enable mariadb

sudo systemctl start mariadb

sudo systemctl status mariadb

Step 5: Secure the MariaDB Installation

Run the included security script:

sudo mysql_secure_installation

Recommended responses:

  • Set root password: Yes
  • Remove anonymous users: Yes
  • Disallow root remote login: Yes
  • Remove test database: Yes
  • Reload privilege tables: Yes

Step 6: Log Into the MariaDB Shell

sudo mariadb

You’re now in the MariaDB shell (MariaDB [(none)]>).

Step 7: Create a Local User

Inside the MariaDB shell:

CREATE USER ‘localuser’@’localhost’ IDENTIFIED BY ‘LocalPassword’;

GRANT ALL PRIVILEGES ON *.* TO ‘localuser’@’localhost’ WITH GRANT OPTION;

FLUSH PRIVILEGES;

This user can only connect locally from the machine running MariaDB.

Step 8: Create a Remote User

8.1 Modify the Bind Address

Exit the MariaDB shell:

exit;

Edit the MariaDB config file:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Find the line:

bind-address = 127.0.0.1

Change it to:

bind-address = 0.0.0.0

This allows connections from any remote IP.

Save and exit (Ctrl+X, then Y, then Enter).

8.2 Restart MariaDB

sudo systemctl restart mariadb

8.3 Create the Remote User

Log back into MariaDB:

sudo mariadb

Create a user that can connect from any IP:

CREATE USER ‘remoteuser’@’%’ IDENTIFIED BY ‘RemotePassword’;

GRANT ALL PRIVILEGES ON *.* TO ‘remoteuser’@’%’ WITH GRANT OPTION;

FLUSH PRIVILEGES;

exit;

You can restrict ‘%’ to a specific IP or subnet like ‘192.168.1.100’ for better security.

Step 9: Configure the Firewall

If you’re using ufw, allow MariaDB’s default port (3306):

sudo ufw allow 3306/tcp

sudo ufw reload

Step 10: Test the Users

Local User

On the local machine:

mariadb -u localuser -p

Enter LocalPassword.

Remote User

From a different computer (must have MariaDB client installed):

mariadb -h your-server-ip -u remoteuser -p

Enter RemotePassword.

Create a Database for the Users

Log in as root or privileged user:

CREATE DATABASE myappdb;

GRANT ALL PRIVILEGES ON myappdb.* TO ‘localuser’@’localhost’;

GRANT ALL PRIVILEGES ON myappdb.* TO ‘remoteuser’@’%’;

FLUSH PRIVILEGES;

MariaDB is a versatile and robust open-source database system used for a wide array of applications requiring reliable, scalable, and high-performance data management. Its commitment to remaining open-source and its compatibility with MySQL have made it a popular choice for developers and organizations worldwide.

Similar Posts