1080*80 ad

Install MariaDB 10.5 on FreeBSD 12.1: A Simple Guide

How to Install and Secure MariaDB on FreeBSD: A Comprehensive Guide

Setting up a powerful, open-source relational database on your FreeBSD server is a crucial step for many applications. MariaDB, a high-performance fork of MySQL, stands out as a leading choice for its stability, robust features, and strong community support. This guide will walk you through the entire process of installing and securing MariaDB on FreeBSD, ensuring your database is ready for production.

Whether you’re powering a dynamic website, managing application data, or learning database administration, this straightforward guide will get you up and running quickly and securely.

Step 1: Update Your System Packages

Before installing new software, it’s always best practice to ensure your system’s package repository is up to date. This guarantees you have the latest security patches and package information.

Open your terminal and run the following command:

sudo pkg update && sudo pkg upgrade

This command first updates the local package catalog and then upgrades any installed packages to their latest versions.

Step 2: Install the MariaDB Server and Client

With your system updated, you can now install the MariaDB packages. FreeBSD’s package manager, pkg, makes this process simple. We will install both the server daemon, which runs the database, and the client, which allows you to connect to it.

The package version may vary, but for this example, we will install MariaDB 10.5. You can search for available versions with pkg search mariadb.

To install the server and client, execute this command:

sudo pkg install mariadb105-server mariadb105-client

The package manager will resolve dependencies and install all the necessary files.

Step 3: Enable the MariaDB Service

For your database server to start automatically when your FreeBSD system boots, you need to enable it in the rc.conf file. The easiest way to do this is with the sysrc utility.

It’s important to note that the service is named mysql-server, a holdover from its shared history with MySQL.

sudo sysrc mysql_enable="YES"

This command adds the line mysql_enable="YES" to your /etc/rc.conf file, telling the system to launch the MariaDB daemon on startup.

Step 4: Start the MariaDB Service

With the service enabled, you can now start it for the first time without needing to reboot. Use the service command to start the MariaDB server.

sudo service mysql-server start

You should see a confirmation message that the service is starting. To verify that it’s running correctly, you can check its status:

sudo service mysql-server status

This command will confirm if the process is active.

Step 5: Secure Your MariaDB Installation

This is the most critical step for any production database. A default MariaDB installation is not secure. It has an anonymous user and a root user with no password. Fortunately, MariaDB includes an interactive script to fix these security holes.

Run the security script now:

mysql_secure_installation

The script will guide you through several essential security questions. Here are the recommended answers for a secure setup:

  1. Enter current password for root (enter for none): Since you just installed it, there is no password. Just press Enter.
  2. Set root password? [Y/n]: Press Y and enter a new, strong password for the database root user. This is not the same as your system’s root user.
  3. Remove anonymous users? [Y/n]: Press Y. Anonymous users are a security risk and are only intended for testing.
  4. Disallow root login remotely? [Y/n]: Press Y. This is a major security enhancement. You should only connect to the database as root from the local machine (localhost). For remote access, you should create dedicated users with limited privileges.
  5. Remove test database and access to it? [Y/n]: Press Y. The test database can be accessed by anyone and should be removed from a production environment.
  6. Reload privilege tables now? [Y/n]: Press Y. This saves all the changes you just made, applying the new security settings immediately.

Step 6: Verify Your Installation

Your MariaDB server is now installed, running, and secured. The final step is to verify that you can log in with the new root password you created.

Attempt to connect to the database as the root user:

mysql -u root -p

The system will prompt you to Enter password:. Type the new MariaDB root password you set in the previous step and press Enter.

If successful, you will be greeted with the MariaDB monitor prompt, which looks like this:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.5.x-MariaDB FreeBSD port

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

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

MariaDB [(none)]>

You can exit the monitor by typing exit and pressing Enter.

Your FreeBSD Database Server is Ready

Congratulations! You have successfully installed, enabled, and secured a MariaDB database server on your FreeBSD system. Your database is now prepared for development or production use. Your next steps might include creating new databases, setting up dedicated user accounts with specific privileges, or integrating MariaDB with your favorite web application or framework.

Source: https://kifarunix.com/easily-install-mariadb-10-5-on-freebsd-12-1/

900*80 ad

      1080*80 ad