How to Install MariaDB on FreeBSD: A Step-by-Step Tutorial
MariaDB is a widely-used open-source relational database management system that can be easily installed on FreeBSD. In this step-by-step tutorial, we will guide you through the process of installing MariaDB on your FreeBSD system.
MariaDB is a widely-used open-source relational database management system that can be easily installed on FreeBSD. In this step-by-step tutorial, we will guide you through the process of installing MariaDB on your FreeBSD system.
Prerequisites
Before you begin, make sure you have:
- A FreeBSD system.
- Root or superuser (sudo) access.
- An active internet connection.
Step 1: Update Your System
First, ensure your FreeBSD system is up to date with the latest software and security updates. Open a terminal and run the following commands:
sudo freebsd-update fetch install
This command will update your system with the latest patches.
Step 2: Install MariaDB
MariaDB is available in the FreeBSD Ports Collection, making it easy to install. Use the following commands to install MariaDB:
sudo pkg install mariadb105-server
This command will fetch and install the MariaDB server.
Step 3: Configure MariaDB
After installation, you need to configure MariaDB. First, enable the service to start at boot by adding the following line to your /etc/rc.conf
file:
echo 'mysql_enable="YES"' | sudo tee -a /etc/rc.conf
Now, initialize the MariaDB data directory and start the service:
sudo mysql_install_db --user=mysql
sudo service mysql-server start
Step 4: Secure Your MariaDB Installation
MariaDB comes with a script that helps you secure your database installation. Run the following command:
sudo mysql_secure_installation
You’ll be prompted to set a root password, remove anonymous users, disallow root login remotely, and remove the test database. Follow the prompts and answer ‘Y’ or ‘N’ as needed.
Step 5: Log In to MariaDB
Now that your MariaDB installation is secure, you can log in to the database server using the following command:
sudo mysql -u root -p
Enter the root password you set during the installation when prompted.
Step 6: Create a New Database and User
To create a new database and user, follow these steps:
-
Log in to MariaDB as the root user.
-
Create a new database (replace
mydatabase
with your preferred name):CREATE DATABASE mydatabase;
-
Create a new user and grant privileges (replace
myuser
andmypassword
with your desired username and password):CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword'; GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES;
-
Exit the MariaDB prompt:
exit;
Step 7: Test Your MariaDB Installation
You can test your new database and user by logging in with the created credentials:
mysql -u myuser -p
Enter the password when prompted, and you should now have access to the database you created.
Conclusion
You’ve successfully installed MariaDB on your FreeBSD system, secured the installation, and created a new database and user. MariaDB is a powerful and reliable database system that can serve as the foundation for various web applications and services. You are now ready to build and manage your databases with MariaDB on FreeBSD.