How to install Mysql Server 8 on FreeBSD 13

MySQL is an open-source relational database management system. Its one of the popular relational management system.

Mysql is commonly installed as part of the popular LAMP or LEMP (Linux, Apache/Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. It implements the relational model and Structured Query Language (SQL) to manage and query data.

In this guide we are going to install mysql 8 on FreeBSD 13.

# Table of Content

  1. Ensuring the server is Up to date
  2. Set up the repo for mysql 8 installation
  3. Installing Mysql 8 server
  4. Starting and enabling mysql service
  5. Configuring mysql
  6. Testing mysql installation

# 1. Ensuring the Server is Up to date

Before proceeding, let us ensure that our debian server is up to date. Use this command to update the server packages:

pkg update 

Next, let us install common packages that we will need in our tutorial

pkg install -y curl vim

# 2. Installing Mysql 8 server

The Mysql server 8 package is available as mysql80-server in freebsd. Install it using this command:

pkg install -y mysql80-server

The system will install the MySQL server package, client packages, and database common files.

# 4. Starting and enabling mysql service

In FreeBSD, Mysql server will be started by default. Enable and start mysql server using these commands. Enable:

# sysrc mysql_enable=yes
mysql_enable:  -> yes

Then start the service

service mysql-server start

Check the status of the service to confirm that it is actually running:

# service mysql-server status
mysql is running as pid 2913.

# 5. Configuring mysql

For new Mysql installations, the next step is to run the included security script. This script changes some of the less secure default options. We will use it to block remote root logins and to remove unused database users.

Run the security script:

sudo mysql_secure_installation

This will take you through a series of prompts where you can make some changes to your Mysql installation‚Äôs security options. The first prompt will ask you to enter the current database¬†root¬†password. Since we have not set one up yet, press¬†ENTER¬†to indicate ‚Äúnone‚ÄĚ.

The next prompt asks you whether you’d like to set up a database root password. Type N and then press ENTER. The root account for Mysql is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Doing so would make it possible for a package update to break the database system by removing access to the administrative account. Later, we will cover how to optionally set up an additional administrative account for password access if socket authentication is not appropriate for your use case.

From there, you can press Y and then ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that Mysql immediately respects the changes you have made.

This is my server’s output

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL Mysql
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into <meta charset="utf-8">Mysql to secure it, we'll need the current
password for the root user. If you've just installed <meta charset="utf-8">Mysql, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the <meta charset="utf-8">Mysql root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n]
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a <meta charset="utf-8">Mysql installation has an anonymous user, allowing anyone
to log into <meta charset="utf-8">Mysql without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]

 ... Success!

By default, <meta charset="utf-8">Mysql comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]  - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your <meta charset="utf-8">Mysql
installation should now be secure.

Thanks for using <meta charset="utf-8">Mysql!

# 6. Testing MySQL Installation

Let us check mysql version with this command:

# mysql -V
mysql  Ver 8.0.27 for FreeBSD13.0 on amd64 (Source distribution)

Now you can Login as the root user and the password specified above.

 # mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

root@localhost [(none)]> select version();
+-----------+
| version() |
+-----------+
| 8.0.27    |
+-----------+
1 row in set (0.00 sec)

root@localhost [(none)]>

# Conclusion

In this article, we managed to install and test Mysql server 8 installation on FreeBSD 13.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy