FreeBSD

Install MariaDB on FreeBSD

MariaDB is a free and open-source derivative of the MySQL database management system. It was developed due to reservations of the MySQL userbase when it was being acquired by Oracle back in 2009. For this reason, it’s quite compatible with MySQL and has only recently deviated a bit with the introduction of source engines, MyRocks, Aria, and Columnstore, to name a few.

This is a quick tutorial on installing MariaDB 10.3 Database Server on a FreeBSD 12 system. By following the instructions here, you’ll be able to set up the database on your own FreeBSD server.

1- Update the FreeBSD Ports collection

Before you install MariaDB, you should update the FreeBSD port tree by issuing the command below:

$ su -

$ portsnap fetch update

To make sure that the portsnap command is properly executed, extract the snapshot into /usr/ports with the command below:

$ sudo portsnap extract

You only need to run the command above just once, when you’re running the portsnap command for the first time. Your output should display a crucial message near the end; ignore it.

To see if you’ve been keeping up with the updates, issue the following command:

$ sudo portsnap fetch update

2- Install MariaDB 10.3 Database Server

Now you’re ready to install MariaDB using the FreeBSD tree ports; it can be installed from its binary package with the FreeBSD package manager.

To see if the latest version of MariaDB can be installed with the FreeBSD package cache, type in the following:

$ pkg search mariadb | grep 10.3

The output clearly indicates that the latest version is FreeBSD 10.x.xx. Issue the command below:

$ sudo pkg install mariadb103-server mariadb103-client

3- Launch the mysql-server service

With MariaDB successfully installed on your FreeBSD server, all there’s left is to enable it before finally using it.

Activate the mysql-server service with the following command:

$ sudo sysrc mysql_enable=yes

This should enable the service to launch upon a reboot. To start the mysql-server service on your FreeBSD, type in:

$ sudo service mysql-server start

4- Perform server hardening for MariaDB

Issue the command below:

$ mysql_secure_installation

You’ll be asked to enter and then re-enter the new password along with a host of other questions that you should all answer yes to. Just make sure that you’ve set the database root password, disabled remote root logins, deleted any anonymous users, and removed the test database from open access.

Perform a test as the root user:

$ mysql -u root -p

Then type out the password.

5- Chain MariaDB service with localhost

Use the sockstat command to see the activities related to our newly installed MariaDB service:

$ sockstat -4 -6 | grep 3306

The output indicates that the service has been integrated with all the network interfaces. Now, it could be that you don’t have the service connected to the network database. If that’s the case, use the command below:

$ sysrc mysql_args="--bind-address=127.0.0.1"

The changes will be made consistent upon a system reboot. To restart the system, type:

$ service mysql-server restart

Once the system has restarted, confirm the changes with the command below:

$ sockstat -4 -6 | grep mysql

Wrapping it up

Hopefully, you’ve got MariaDB up and running on your FreeBSD system. The features included with the latest MariaDB install are:

  • You get InnoDB(with an instant add column as well) as the default storage engine for MariaDB.
  • Parallel and Multi-source replication.
  • You can use FOR loops with MariaDB.
  • Transparent columns.
  • The latest versions come with Galera Cluster.
  • You can add Sequences.
  • Column compressions are now independent of the storage-engine.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.