How to Install and Configure MariaDB on FreeBSD 14 and 15

Install MariaDB on FreeBSD 14 or 15: add the server package with pkg, start and enable the service, secure it with mariadb-secure-installation, and test.

In this guide we will learn how to install and configure MariaDB on FreeBSD.

MariaDB is an open-source one of the most popular relational database management system (RDBMS) that is a highly compatible drop-in replacement of MySQL. It is built upon the values of performance, stability, and openness, and MariaDB Foundation ensures contributions will be accepted on technical merit.

MariaDB was developed as a software fork of MySQL in 2009 in response to Oracle’s acquisition of MySQL. MariaDB intends to remain free and open-source software under the GNU General Public License. It is part of most cloud offerings and the default in most Linux distributions.

Updated for 2026. This guide was originally written for FreeBSD 13 and MariaDB 10.5, both of which have since reached end of life — FreeBSD 13 is no longer a supported branch, and MariaDB 10.5 stopped receiving fixes in June 2025. The steps below now target the supported FreeBSD 14.x and 15.x branches and a current MariaDB LTS release. The commands themselves are unchanged in shape, so they still work on older systems; only the package names and versions differ.

Related Posts:

Prerequisites:

To follow along, ensure you have:

  • An up to date FreeBSD server/workstation — FreeBSD 14.x or 15.x, since FreeBSD 13 is end of life
  • Root access to the server or a user with sudo access
  • Access to the internet from the server

Ensure that the system is up to date

Before proceeding let us ensure that the FreeBSD server is up to date. We will use the pkg command as a root user if you don’t have sudo installed:

1
2
pkg update
pkg upgrade

pkg update only refreshes the local copy of the package catalogue; pkg upgrade is what actually installs the newer packages.

Installing MariaDB in FreeBSD

MariaDB can be found in the default FreeBSD repos. To search the name of the package, use this command:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ pkg search mariadb

mariadb-connector-c-3.4.8        MariaDB database connector for C
mariadb-connector-odbc-3.2.8     MariaDB database connector for odbc
mariadb1011-client-10.11.18      Multithreaded SQL database (client)
mariadb1011-server-10.11.18      Multithreaded SQL database (server)
mariadb114-client-11.4.12        Multithreaded SQL database (client)
mariadb114-server-11.4.12        Multithreaded SQL database (server)
mariadb118-client-11.8.8         Multithreaded SQL database (client)
mariadb118-server-11.8.8         Multithreaded SQL database (server)
mariadb123-client-12.3.2         Multithreaded SQL database (client)
mariadb123-server-12.3.2         Multithreaded SQL database (server)
p5-DBD-MariaDB-1.23              MariaDB driver for the Perl5 Database Interface (DBI)

The exact point releases you see will differ as the ports tree moves — what matters is the major version you pick. FreeBSD ships several in parallel, and the port name encodes the version with the dot removed (mariadb114-server is MariaDB 11.4). Only the LTS releases are worth running on a server:

PortMariaDBCommunity support until
mariadb1011-server10.11 LTSFebruary 2028
mariadb114-server11.4 LTSMay 2029
mariadb118-server11.8 LTSJune 2028
mariadb123-server12.3 LTSJune 2029

The mariadb105-* packages this guide originally used are gone: MariaDB 10.5 reached end of life in June 2025 and 10.6 followed in July 2026. If you are still running either, plan an upgrade — they no longer get security fixes.

For a new install, 11.4 LTS is the safe default: it is well past its initial release, widely deployed, and supported into 2029. Install the server and the matching client:

1
pkg install mariadb114-server mariadb114-client

Stick to one major version — the MariaDB server ports conflict with each other, so pkg will refuse to install mariadb114-server alongside, say, mariadb1011-server.

Starting and enabling MariaDB

MariaDB will not be started by default. The FreeBSD ports still name the rc script mysql-server and the rc variable mysql_enable regardless of the MariaDB version you installed, so enable start on boot first:

1
2
3
$ sysrc mysql_enable="YES"

mysql_enable:  -> YES

Then start the service:

1
service mysql-server start

Confirm that the service is up and running by checking its status

1
2
3
$ service mysql-server status

mysql is running as pid 1371.

Configuring MariaDB

For new MariaDB installations, the next step is to run the included security script. This script changes some of the less secure default options. We will use it to block remote root logins and to remove unused database users.

Run the security script:

1
sudo mariadb-secure-installation

Since MariaDB 10.5, the client tools have been renamed to a mariadb-* prefix — mariadb-secure-installation, mariadb-admin, mariadb-dump, and the mariadb client itself. The old mysql_secure_installation, mysqladmin, and mysql names still exist as symlinks for compatibility, so both work today, but the mariadb-* names are the ones to use going forward.

This will take you through a series of prompts where you can make some changes to your MariaDB installation’s security options. The first prompt asks for the current database root password. A fresh install from ports does not have one, so press ENTER to indicate “none”.

The next prompt asks whether you want to switch to unix_socket authentication. Answer Y. This ties the database root user to the operating system’s root account: anyone already logged in as root on the box can run mariadb with no password, and nobody else can log in as database root at all, password or not. It removes the password as something to guess, leak, or leave in a script.

You will then be asked whether to change the root password. With unix_socket authentication enabled this is optional — you can safely answer n and rely on socket auth alone. Set one only if you need to reach the root account some other way; if you do, choose a strong password and store it in a password manager.

From there, you can press Y and then ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MariaDB immediately respects the changes you have made.

This is my server’s output (taken on a run where a root password was also set):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$ 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]
Enabled successfully!
Reloading privilege tables..
 ... Success!

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

Change the root password? [Y/n]
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]
 ... 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]

 ... 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]  - 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]
 ... 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!

Testing MariaDB

Now that MariaDB is all set up and is running, we need to confirm that it can accept connections.

To test, connect to MariaDB with the root user - mariadb -h 127.0.0.1 -u root -p

Output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ mariadb -h 127.0.0.1 -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 11.4.12-MariaDB FreeBSD Ports

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

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

[email protected] [(none)]>

Note that this connects over TCP to 127.0.0.1, which is why it prompts for a password. If you enabled unix_socket authentication and did not set a root password, connect over the socket instead — as the system root user, plain mariadb gets you in with no password.

Check the MariaDB version:

1
2
3
4
5
6
7
8
9
root@127.0.0.1 [(none)]> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 11.4.12-MariaDB |
+-----------------+
1 row in set (0.001 sec)

root@127.0.0.1 [(none)]>

For an additional check, you can try connecting to the database using the mariadb-admin tool (formerly mysqladmin), which is a client that lets you run administrative commands. For example, this command says to connect to MariaDB as root and return the version using the Unix socket:

1
mariadb-admin version

You should receive output similar to this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ mariadb-admin version

mariadb-admin  Ver 9.1 Distrib 11.4.12-MariaDB, for FreeBSD14.4 on amd64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version  11.4.12-MariaDB
Protocol version 10
Connection  Localhost via UNIX socket
UNIX socket  /var/run/mysql/mysql.sock
Uptime:   16 min 9 sec

Threads: 1  Questions: 25  Slow queries: 0  Opens: 21  Open tables: 14  Queries per second avg: 0.025

This means that MariaDB is up and running and that your user is able to authenticate successfully.

Conclusion

In this guide you installed MariaDB to act as an SQL server. During the installation process you also secured the server.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy