Install and Secure MariaDB on FreeBSD 14.0

MariaDB is an open-source relational database management system (RDBMS) that serves as a drop-in replacement for MySQL, offering improved performance and extended support for multiple storage engines. It uses SQL (Structured Query Language) to perform database operations and integrates easily with existing server applications, such as web server stacks, through modular extensions.

This guide explains how to install MariaDB on FreeBSD 14.0, secure the database server, and allow users to create and manage SQL records efficiently.

Prerequisites

  • Deploy a FreeBSD 14.0 server instance via our custom images feature during the server deployment in the ccloud³.
  • Access the server via SSH.
  • Create a non-root user with sudo privileges and switch to that user.

Install MariaDB

MariaDB is included in the default FreeBSD 14.0 package repositories. Follow the steps below to install MariaDB using the pkg package manager and configure it to start automatically at boot.

Update the pkg catalog:

Search for available MariaDB packages:

Install the latest stable version, for example MariaDB 10.6:

$ sudo pkg install -y mariadb106-server

Check the installed MariaDB version:

Temporarily start the MariaDB service to verify access:

$ sudo service mysql-server onestart

Log in to the MariaDB console:

If you see an error like:

ERROR 2002 (HY000): Can't connect to local server through socket '/var/run/mysql/mysql.sock' (2)

Downgrade to a previous stable version (for example, 10.5):

$ sudo pkg remove -y mariadb106-server && sudo pkg install -y mariadb105-server

Manage the MariaDB Service

MariaDB uses the mysql-server service to control the database process. The steps below show how to manage it and enable autostart at boot.

Enable MariaDB autostart:

$ sudo sysrc mysql_enable="YES"

Start the MariaDB service:

$ sudo service mysql-server start

Check the MariaDB service status:

$ sudo service mysql-server status

Secure MariaDB

By default, MariaDB allows root login without a password. Secure your installation using the included setup script:

Run the security script:

$ sudo mysql_secure_installation

Follow the prompts to:

  • Set a strong root password.
  • Disable anonymous users.
  • Prevent remote root access.
  • Remove the test database.
  • Reload privileges to apply changes.

Access the MariaDB Console

MariaDB can be accessed using the mysql or mariadb client tools. The following steps show how to log in and test basic operations.

Log in as root:

Create a new sample database:

List all databases to verify creation:

Switch to the new database:

Create a new user and grant privileges:

CREATE USER 'db_admin'@'localhost' IDENTIFIED BY 'strong-password';
GRANT ALL PRIVILEGES ON demodb.* TO 'db_admin'@'localhost';
FLUSH PRIVILEGES;

Exit the console:

Test the new user login:

$ sudo mysql -u db_admin -p

Display all databases accessible to the user:

Conclusion

You have successfully installed MariaDB on FreeBSD 14.0, secured the server, and configured authentication for database users. MariaDB can now serve as a secure and high-performance database backend for your applications. To make it accessible remotely, adjust the bind address in the configuration file from localhost to 0.0.0.0 or your network’s private IP.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: