Home Alpine Linux How to Install MariaDB on Alpine Linux

How to Install MariaDB on Alpine Linux

MariaDB is a popular open-source relational database server that was forked from MySQL, which is fast, scalable, and provides a rich ecosystem of plugins, storage engines, and other tools that make it more flexible and reliable than MySQL.

In this guide, we demonstrate how to install MariaDB on Alpine Linux.

Step 1: Install MariaDB on Alpine Linux

To get started, log in to your Alpine Linux instance and refresh the repositories by running the following apk command:

# apk update

MariaDB is provided by the official Alpine Linux repositories. Currently, the latest version of MariaDB provided by the repositories is MariaDB 10.6.7.

To install MariaDB, use the apk package manager as follows.

# apk add mariadb mariadb-client

This installs the MariaDB database server and client alongside other additional packages and dependencies.

Install MariaDB in Alpine Linux
Install MariaDB in Alpine Linux

To confirm if MariaDB is installed, run the following command:

# apk search mariadb

The output lists all the MariaDB packages that have been installed.

List MariaDB Packages in Alpine Linux
List MariaDB Packages in Alpine Linux

Additionally, you can check the version installed as follows:

# apk info mariadb
Check MariaDB in Alpine Linux
Check MariaDB in Alpine Linux

By default, MariaDB does not start automatically upon installation. You can confirm its status using the command:

# rc-service mariadb status
Check MariaDB Status
Check MariaDB Status

To start the MariaDB service, first, initialize a new database using the command:

# /etc/init.d/mariadb setup
Initialize MariaDB Database
Initialize MariaDB Database

Next, start the database service as follows.

# rc-service mariadb start

To confirm that the database service is running, execute the command:

# rc-service mariadb status

Additionally, enable the service to start on boot time.

# rc-update add mariadb default
Enable MariaDB on Boot
Enable MariaDB on Boot

Step 2: Secure MariaDB on Alpine Linux

The default settings of MariaDB are weak and make it vulnerable to attacks. For example, it comes with a root password without a configured password.

To test this, run the following command

# mysql -u root -p

Press ENTER when prompted for a password to access the MariaDB shell.

Access MariaDB Shell
Access MariaDB Shell

To exit the shell, run the exit command.

To secure the database server, execute the following script.

# mysql_secure_installation

Press ENTER since no root password is configured yet.

Run MySQL Security Script
Run MySQL Security Script

Next, switch to unix_socket_authentication by pressing 'Y'. Then set the root password and provide a strong root password.

Set MySQL Root Password
Set MySQL Root Password

For the remaining prompts, press 'Y' to harden the database server to the recommended standards.

Secure MariaDB Server
Secure MariaDB Server

The next time you try logging in you will be prompted for a password.

This concludes this guide. We hope you can now comfortably install MariaDB on Alpine Linux.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.