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.
To confirm if MariaDB is installed, run the following command:
# apk search mariadb
The output lists all the MariaDB packages that have been installed.
Additionally, you can check the version installed as follows:
# apk info mariadb
By default, MariaDB does not start automatically upon installation. You can confirm its status using the command:
# rc-service mariadb status
To start the MariaDB service, first, initialize a new database using the command:
# /etc/init.d/mariadb setup
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
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.
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.
Next, switch to unix_socket_authentication by pressing 'Y'
. Then set the root password and provide a strong root password.
For the remaining prompts, press 'Y'
to harden the database server to the recommended standards.
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.