How To Install MariaDB 11.4 on Alpine Linux

Today’s tutorial is geared towards setting up MariaDB Database Server on Alpine Linux instance. The machine can be running on Virtualized environment powered by KVM, VirtualBox, VMware, Parallels, Hyper-V or Cloud provider that provides alpine Linux servers. For those new to MariaDB it is a relational database management system that is developed by the community, but was forked from MySQL. The software is open source and released under the GNU General Public License.

As of this article update the latest stable release of MariaDB database server is version 11.8 but the version on the Alpine Linux repositories is 11.4. This guide will capture MariaDB database server installation on Alpine Linux. Once a much newer release is available the title of this article will be updated to capture it.

Install MariaDB 11.4 on Alpine Linux

Before we even begin the actual installation we need to make sure our system can connect to the OS repositories for package installation.

Update APK application list cache:

alpine:~$ sudo apk update
v3.22.0-187-g8bf0f43c33c [http://alpine.mirror.wearetriple.com/v3.22/main]
v3.22.0-188-gdd4c63b8165 [http://alpine.mirror.wearetriple.com/v3.22/community]
OK: 26311 distinct packages available
alpine:~$ sudo apk upgrade

Check for package names that match mariadb:

$ sudo apk search mariadb
acf-mariadb-0.2.0-r5
freeswitch-mariadb-1.10.12-r0
mariadb-11.4.5-r2
mariadb-backup-11.4.5-r2
mariadb-bench-11.4.5-r2
mariadb-client-11.4.5-r2
mariadb-client-perl-11.4.5-r2
mariadb-common-11.4.5-r2
mariadb-connector-c-3.3.10-r0
mariadb-connector-c-dev-3.3.10-r0
mariadb-connector-odbc-3.2.4-r0
mariadb-dev-11.4.5-r2
mariadb-doc-11.4.5-r2
mariadb-embedded-11.4.5-r2
mariadb-embedded-dev-11.4.5-r2
mariadb-mytop-11.4.5-r2
mariadb-openrc-11.4.5-r2
mariadb-plugin-rocksdb-11.4.5-r2
mariadb-server-utils-11.4.5-r2
mariadb-static-11.4.5-r2
mariadb-test-11.4.5-r2
pdns-backend-mariadb-4.9.5-r0

Install MariaDB 11.4 on Alpine Linux

From the list we can confirm availability of MariaDB on the Alpine Linux repositories.

$ sudo apk add mariadb mariadb-common mariadb-client
(1/19) Installing mariadb-common (11.4.5-r2)
(2/19) Installing libaio (0.3.113-r2)
(3/19) Installing brotli-libs (1.1.0-r2)
(4/19) Installing c-ares (1.34.5-r0)
(5/19) Installing libunistring (1.3-r0)
(6/19) Installing libidn2 (2.3.7-r0)
(7/19) Installing nghttp2-libs (1.65.0-r0)
(8/19) Installing libpsl (0.21.5-r3)
(9/19) Installing libcurl (8.14.1-r0)
(10/19) Installing libgcc (14.2.0-r6)
(11/19) Installing skalibs-libs (2.14.4.0-r0)
(12/19) Installing utmps-libs (0.1.3.1-r0)
(13/19) Installing linux-pam (1.7.0-r4)
(14/19) Installing pcre2 (10.43-r1)
(15/19) Installing libstdc++ (14.2.0-r6)
(16/19) Installing libxml2 (2.13.8-r0)
(17/19) Installing mariadb (11.4.5-r2)
Executing mariadb-11.4.5-r2.pre-install
(18/19) Installing mariadb-openrc (11.4.5-r2)
(19/19) Installing mariadb-client (11.4.5-r2)
Executing busybox-1.37.0-r18.trigger
OK: 404 MiB in 83 packages

After installation you need to initialize the main mysql database, and the data dir as standardized to /var/lib/mysql. This can be done by executing the rc script below.

$ sudo /etc/init.d/mariadb setup
 * Creating a new MySQL database ...
/usr/bin/mysql_install_db: Deprecated program name. It will be removed in a future release, use 'mariadb-install-db' instead
WARNING: The host 'alpinelinux.local' could not be looked up with /usr/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mariadbd, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK

To start mariadbd at boot time you have to copy
support-files/mariadb.service to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mariadbd-safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mariadb-test-run.pl
cd '/usr/mariadb-test' ; perl mariadb-test-run.pl

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.

Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

Start MariaDB database service on Alpine Linux.

Alpine Linux uses OpenRC for its init system. The service can be started using the command:

$ sudo rc-service mariadb start
 * Caching service dependencies ...                                                                                                                                                                 [ ok ]
 * Starting mariadb ...
/usr/bin/mysqld_safe: Deprecated program name. It will be removed in a future release, use 'mariadbd-safe' instead
250619 00:42:40 mysqld_safe Logging to syslog.
250619 00:42:40 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql                                                                                                             [ ok ]

Also set the service to be started at system boot.

$ sudo rc-update add mariadb default
* service mariadb added to runlevel default

Check service status with rc-status command:

$ rc-status default
Runlevel: default
 acpid                                                                                                                                                                                       [  started  ]
 sshd                                                                                                                                                                                        [  started  ]
 crond                                                                                                                                                                                       [  started  ]
 mariadb                                                                                                                                                                                     [  started  ]

Secure MariaDB database server on Alpine Linux

Now that the service is running the only pending item is securing it. Run the command below to set root password, remove test database and disallow remote login as root user.

$ sudo mariadb-secure-installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

If you try accessing the database console without providing password an access denied error will be shown.

$ mariadb -u root <ENTER>
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Now try again but this time providing the password with -p command option.

$ mariadb -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 11.4.5-MariaDB Alpine Linux

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Test MariaDB database installation on Alpine Linux

Create test database and user.

MariaDB [(none)]> CREATE DATABASE testdb;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| testdb             |
+--------------------+
4 rows in set (0.000 sec)

Create a user and grant access to the database created.

MariaDB [(none)]> CREATE USER testuser@localhost IDENTIFIED BY "STr0ngDBP@ss";
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> GRANT ALL ON testdb.* TO testuser@localhost;
Query OK, 0 rows affected (0.003 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

Quit from MariDB console and login as testuser.

MariaDB [(none)]> QUIT
Bye

$ mariadb -u testuser -p'STr0ngDBP@ss'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 11.4.5-MariaDB Alpine Linux

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

List the databases that the user has access to.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| testdb             |
+--------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]> QUIT
Bye

We have successfully installed, configured and started MariaDB database server on Alpine Linux virtual machine. We also demonstrated how you can create a database, user and grant permissions and we confirmed the user was able to see database when permissions were granted. You can now proceed to learn more about SQL and hack your projects with confidence.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Unlock the Right Solutions with Confidence

At CloudSpinx, we don’t just offer services - we deliver clarity, direction, and results. Whether you're navigating cloud adoption, scaling infrastructure, or solving DevOps challenges, our seasoned experts help you make smart, strategic decisions with total confidence. Let us turn complexity into opportunity and bring your vision to life.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

Zabbix is a free to use monitoring solution that can be installed on most Linux distribution servers. Zabbix gives you […]

In this blog post we will show you how to install ejabberd on Amazon Linux 2023. ejabberd is an open-source, […]

MongoDB is an open-source document-oriented cross-platform database system. It stores data in JSON-like documents which offers high flexibility and dynamism […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.