Menu

How to Install MariaDB on FreeBSD

Install MariaDB 11.8 on FreeBSD with pkg, enable the mysql-server service, secure the installation, and create a least-privilege database user.

Posted on By Updated on
On this page

This guide installs MariaDB 11.8 on a supported FreeBSD release using the binary package. The FreeBSD Ports tree provides the mariadb118-server package, and its service is managed as mysql-server.

Prerequisites

  • A supported FreeBSD release with network access.
  • A root shell, or an account allowed to use sudo.

1. Update package metadata

Refresh the package catalog before installing software:

sudo pkg update

If you also need to apply operating-system updates, follow the FreeBSD Handbook update instructions. pkg update refreshes package metadata; it does not update the FreeBSD base system.

2. Install MariaDB 11.8

sudo pkg install mariadb118-server

The package installs the server and its dependencies. If you need another MariaDB branch, search the configured repository with pkg search mariadb and choose a supported server package.

3. Enable and start the service

Enable MariaDB at boot and start it now:

sudo sysrc mysql_enable="YES"
sudo service mysql-server start

The port supplies the mysql-server rc service. The package installation message may include release-specific details; review it if it appears during installation.

4. Secure the initial installation

Run MariaDB’s security setup utility:

sudo mariadb-secure-installation

Follow the prompts to remove anonymous accounts, disallow remote root login, and remove the test database if present. On installations that do not provide the mariadb-secure-installation command, try its compatibility name:

sudo mysql_secure_installation

5. Connect to MariaDB

On a default local installation, connect through the local administrative account:

sudo mariadb

If your setup requires password authentication, use sudo mariadb -u root -p and enter the password when prompted.

6. Create a database and application account

In the MariaDB prompt, create a database and a runtime account. Use a unique secret stored in a password manager. This account has data-manipulation privileges only; use a separate account for schema migrations.

CREATE DATABASE mydatabase;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'replace-with-a-unique-secret';
GRANT SELECT, INSERT, UPDATE, DELETE ON mydatabase.* TO 'myuser'@'localhost';

Exit the client:

exit;

Test the application account locally:

mariadb -u myuser -p mydatabase

Enter the account password when prompted. For applications connecting over a network, create a host-restricted account appropriate to the application server and configure the firewall and MariaDB network binding deliberately.

Troubleshooting

  • Check service state with sudo service mysql-server status.
  • Review the package-provided MariaDB configuration and logs if startup fails.
  • If pkg install mariadb118-server cannot find the package, refresh the repository catalog and check available versions with pkg search mariadb.

Conclusion

MariaDB is installed as a FreeBSD package, enabled through the native rc system, and ready for local use with a restricted application account. See the MariaDB reference for SQL and server documentation.