Databases

Install MariaDB 11.4 on FreeBSD 15

Most database servers run on Linux, but FreeBSD remains a solid choice for production workloads where stability and long-term support matter. MariaDB fits naturally into the FreeBSD ecosystem, with packages maintained in the official ports tree and a straightforward installation process that takes just a few minutes.

Original content from computingforgeeks.com - post 5145

This guide walks through installing MariaDB 11.4 LTS on FreeBSD 15, covering package installation, service management, security hardening, user creation, remote access configuration, and backup procedures. Whether you are setting up a standalone database server or the backend for a web application stack, these steps will get MariaDB running and properly secured on FreeBSD 15.0-RELEASE.

Last verified: March 2026 | Tested on FreeBSD 15.0-RELEASE, MariaDB 11.4.9 LTS

Prerequisites

Before you begin, make sure you have:

Install MariaDB on FreeBSD 15

FreeBSD’s package repository carries several MariaDB versions. Search for available packages to see what’s offered:

pkg search mariadb | grep server

The output lists all available MariaDB server packages:

mariadb106-server-10.6.24      Multithreaded SQL database (server)
mariadb1011-server-10.11.15    Multithreaded SQL database (server)
mariadb114-server-11.4.9       Multithreaded SQL database (server)
mariadb118-server-11.8.5       Multithreaded SQL database (server)

MariaDB 11.4 is the current Long Term Support (LTS) release, making it the best choice for production use. Install both the server and client packages:

pkg install -y mariadb114-server mariadb114-client

This installs mariadb114-server-11.4.9 and mariadb114-client-11.4.9 along with all required dependencies.

Enable and Start MariaDB

FreeBSD services must be explicitly enabled in /etc/rc.conf before they can start. Use sysrc to enable MariaDB:

sysrc mysql_enable=YES

The command confirms the change:

mysql_enable:  -> YES

Now start the MariaDB service. On first start, it automatically initializes the system tables in /var/db/mysql:

service mysql-server start

You should see the initialization output followed by the startup confirmation:

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

Verify the service is running:

service mysql-server status

The output confirms MariaDB is active:

mysql is running as pid 3074.

Check the installed version to confirm everything is correct:

mariadb --version

This should return the version string:

mariadb from 11.4.9-MariaDB, client 15.2 for FreeBSD15.0 (amd64)

Secure the Installation

By default, MariaDB’s root account has no password and a test database exists that anyone can access. Fix both of these immediately.

Set a strong root password:

mariadb -u root -e "ALTER USER root@localhost IDENTIFIED BY 'StrongDBPass2026'; FLUSH PRIVILEGES;"

Verify the new password works by running a version check with authentication:

mariadb -u root -p"StrongDBPass2026" -e "SELECT VERSION();"

A successful login returns the version:

+------------------+
| VERSION()        |
+------------------+
| 11.4.9-MariaDB   |
+------------------+

Remove the test database and anonymous users. Log into the MariaDB shell first:

mariadb -u root -p"StrongDBPass2026"

Run these cleanup commands inside the MariaDB prompt:

DROP DATABASE IF EXISTS test;
DELETE FROM mysql.global_priv WHERE User='';
FLUSH PRIVILEGES;
EXIT;

Confirm the remaining databases are only the essential system ones:

mariadb -u root -p"StrongDBPass2026" -e "SHOW DATABASES;"

You should see only the system databases:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Create Databases and Users

With MariaDB secured, you can create application databases and dedicated users. Never use the root account for application connections.

Log into MariaDB:

mariadb -u root -p"StrongDBPass2026"

Create a new database:

CREATE DATABASE testdb;

Create a user with a strong password and grant full privileges on the new database:

CREATE USER testuser@localhost IDENTIFIED BY 'TestPass123';
GRANT ALL PRIVILEGES ON testdb.* TO testuser@localhost;
FLUSH PRIVILEGES;
EXIT;

Test the new user’s access by connecting with those credentials:

mariadb -u testuser -p"TestPass123" -e "SHOW DATABASES;"

The user should see only their granted database plus the default schema:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| testdb             |
+--------------------+

Configure Remote Access

By default, MariaDB only listens on the local Unix socket at /var/run/mysql/mysql.sock. If other servers need to connect to this database, you need to bind MariaDB to a network address.

Create a custom configuration file in the MariaDB config directory:

vi /usr/local/etc/mysql/conf.d/server.cnf

Add the following configuration to listen on all interfaces:

[mysqld]
bind-address = 0.0.0.0

To bind to a specific IP instead of all interfaces, replace 0.0.0.0 with your server’s IP address, for example 192.168.1.10.

Restart MariaDB to apply the change:

service mysql-server restart

Verify MariaDB is listening on port 3306:

sockstat -4 -l | grep 3306

You also need to create a user account that allows remote connections. Replace 192.168.1.20 with the IP of the client that will connect:

mariadb -u root -p"StrongDBPass2026" -e "CREATE USER appuser@'192.168.1.20' IDENTIFIED BY 'RemotePass2026'; GRANT ALL PRIVILEGES ON testdb.* TO appuser@'192.168.1.20'; FLUSH PRIVILEGES;"

FreeBSD does not have a firewall enabled by default. If you are running pf (FreeBSD’s packet filter), add a rule to allow TCP traffic on port 3306:

vi /etc/pf.conf

Add the following rule to your existing ruleset:

pass in on egress proto tcp from 192.168.1.0/24 to any port 3306

Reload the firewall rules:

pfctl -f /etc/pf.conf

Limiting access to your local subnet is recommended. Exposing port 3306 to the public internet is a serious security risk.

Backup and Restore

Regular backups are non-negotiable for any production database. MariaDB ships with mariadb-dump, which creates logical SQL dumps that are portable and easy to restore.

Back up a single database:

mariadb-dump -u root -p"StrongDBPass2026" testdb > /var/db/mysql/backups/testdb_backup.sql

Back up all databases at once:

mariadb-dump -u root -p"StrongDBPass2026" --all-databases > /var/db/mysql/backups/all_databases_backup.sql

Create the backup directory first if it does not exist:

mkdir -p /var/db/mysql/backups

To restore a database from a backup file:

mariadb -u root -p"StrongDBPass2026" testdb < /var/db/mysql/backups/testdb_backup.sql

For automated daily backups, add a cron job that runs mariadb-dump and removes backups older than 7 days:

crontab -e

Add the following line:

0 2 * * * /usr/local/bin/mariadb-dump -u root -p"StrongDBPass2026" --all-databases | /usr/bin/gzip > /var/db/mysql/backups/all_db_$(date +\%F).sql.gz && find /var/db/mysql/backups -name "*.sql.gz" -mtime +7 -delete

Useful MariaDB Commands

Here is a quick reference table of commands you will use frequently when managing MariaDB on FreeBSD:

TaskCommand
Start MariaDBservice mysql-server start
Stop MariaDBservice mysql-server stop
Restart MariaDBservice mysql-server restart
Check statusservice mysql-server status
Enable at bootsysrc mysql_enable=YES
Connect as rootmariadb -u root -p
Show all databasesSHOW DATABASES;
Show tables in a databaseUSE dbname; SHOW TABLES;
Check server variablesSHOW VARIABLES LIKE '%max_connections%';
View active connectionsSHOW PROCESSLIST;
Check binary log statusSHOW MASTER STATUS;
View error logtail -50 /var/db/mysql/hostname.err
Dump single databasemariadb-dump -u root -p dbname > backup.sql
Restore from dumpmariadb -u root -p dbname < backup.sql

Conclusion

MariaDB 11.4 LTS runs well on FreeBSD 15, with packages that stay current and a service management model that feels familiar to anyone used to rc.d. The key configuration paths to remember are /usr/local/etc/mysql/ for config files and /var/db/mysql/ for data. Keep your root password strong, create dedicated users for each application, and set up automated backups from day one.

For more details on MariaDB configuration options, tuning, and replication setup, refer to the official MariaDB documentation.

Related Articles

Databases Install FireBird Database on Debian 12 | Debian 11 Prometheus Monitor Redis Server with Prometheus and Grafana in 5 minutes Databases Monitoring MySQL and MongoDB with Prometheus and Grafana – PMM Databases How To Install Microsoft SQL Server 2022 on Ubuntu 20.04

Leave a Comment

Press ESC to close