MariaDB 11.4 on OpenBSD 7.8: Install

Table of contents

Summary Summary

MariaDB (opens in a new tab) is one of the most popular relational database management systems (RDBMS), forked from MySQL (opens in a new tab) by some of the original developers. It is open source licensed (opens in a new tab) under GNU GPL 2 (opens in a new tab), and ready for both community and enterprise use with long history and large knowledge to manage and maintain.

To Install it on OpenBSD (opens in a new tab), the solid and clean operating system, is easy thanks to the Package Management (opens in a new tab) system (“ports”) maintained by the great project and the community.

This post shows how to do it.

Environment Environment

Basic steps Basic steps

Just a few !!

console
# pkg_add mariadb-server
# rcctl enable mysqld

# mariadb-install-db

# rcctl start mysqld

# mariadb-secure-installation
# # several questions will be given

All of the description is below.

Tutorial Tutorial

Install the package Install the package

console
$ doas pkg_add mariadb-server

The result was:

console
quirks-7.147 signed on 2025-12-01T09:05:47Z
mariadb-server-11.4.9v1:(...): ok
mariadb-server-11.4.9v1: ok
The following new rcscripts were installed: /etc/rc.d/mysqld
See rcctl(8) for details.
New and changed readme(s):
	/usr/local/share/doc/pkg-readmes/mariadb-server

As above, the pkg-readme is brought as /usr/local/share/doc/pkg-readmes/mariadb-server.

Activate daemon Activate daemon

console
$ doas rcctl enable mysqld

Run mariadb-install-db Run mariadb-install-db

Create the default database:

console
$ doas mariadb-install-db

The result was:

console
Installing MariaDB/MySQL system tables in '/var/mysql' ...
OK


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 mariadb
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:
/etc/rc.d/mysqld start

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 daemon Start daemon

console
$ doas rcctl start mysqld
mysqld(ok)

Run mariadb-secure-installation Run mariadb-secure-installation

console
$ doas mariadb-secure-installation

Start (Before the questions) Start (Before the questions)

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

Several questions given Several questions given

Q1: Current root password Q1: Current root password

It must be none for the first time. Just push Enter.

console
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...

At all the questions below, my choice is written down. Actually, they are up to your environment.

Q2: Use unix_socket authentication instead of root password Q2: Use unix_socket authentication instead of root password
console
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.
Q3: Set root password Q3: Set root password
console
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!
Q4: Remove anonymous users Q4: Remove anonymous users
console
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!
Q5: Disallow root login remotely Q5: Disallow root login remotely
console
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!
Q6: Remove test database Q6: Remove test database
console
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!
Q7: Reload privilege tables Q7: Reload privilege tables
console
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

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

End (The rest) End (The rest)

console
Cleaning up...

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

Thanks for using MariaDB!

Conclusion Conclusion

You may confirm your daemon is fine with:

console
$ doas rcctl check mysqld
mysqld(ok)

Well, let’s login to the server as client with root, the superuser:

console
$ mysql -u root -p

After entering the password, you must be welcomed:

console
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 11.4.9-MariaDB OpenBSD port: mariadb-server-11.4.9v1

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)]>

The command line examples:

sql
-- create database
CREATE DATABASE <database> \
    CHARACTER SET utf8mb4 \
    COLLATE utf8mb4_unicode_ci;

-- create user for it
GRANT ALL PRIVILEGES \
    ON <database>.* \
    TO <dbuser>@'localhost' \
    IDENTIFIED BY '<dbpass>';

-- reload privileges
FLUSH PRIVILEGES;

🎵 🐬 Happy storing digitally 🐬 🎵

More on: Run a database on your server

OBSD Solutions

OBSD Solutions: OpenBSD consulting and support by Scqr, Reflerd Inc. (opens in a new tab)

Comments and feedback are welcome.