This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has sudo access and that you precede each of the privileged commands with sudo

MySQL is an open-source relational database management system.It is based on structured language theory. MySQL is inculcated with an ability that it can run on all platforms including Linux, Unix and Windows. It can be used for wide variety of applications but mostly it is associated with online publishing and web applications.

Configuring Ports Collection

In this method the port collection should be installed first if they were not installed already. The port collection is stored as a subdirectory of /usr/ports by default. The Specific port collection should then be located under /usr/ports/databases/mysql80-server and /usr/ports/databases/mysql80-client respectively.

ls /usr/ports/databases/mysql80-{server,client}
Makefile	files		pkg-message	pkg-plist

Makefile	distinfo	files		pkg-descr	pkg-message	pkg-plist

Once the ports are installed,you will proceed to install MySQL 8

Installing MySQL 8

You have to navigate to MySQL 8 subdirectory and run make install to install MySQL 8 server. The clean command removes the temporary files generated during compilation

cd /usr/ports/databases/mysql80-server
make install clean

After compilation, following output will appear.

      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.

      This port has installed the following startup scripts which may cause
      these network services to be started at boot time.

      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type 'make deinstall'
      to deinstall the port if this is a concern.

      For more information, and contact details about the security
      status of this software, see the following webpage:

FreeBSD pkg has a built in mechanism to detect any known vulnerabilities in the software installed in the system

pkg audit -F
Fetching vuln.xml.bz2: 100%  793 KiB 405.9kB/s    00:02    
0 problem(s) in the installed packages found.

Running MySQL

Next you will run the command below, this will add MySQL service to /etc/rc.conf

sysrc mysql_enable=yes

Start the MySQL service using

service mysql-server start

Check the service status

service mysql-server status
mysql is running as pid 63804.

Securing MySQL

For MySQL security initialization you will run following script

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

The script would ask about validation of password component. It will prompts you on whether to enforce password complexity. Type Y and press Enter to enable or any other key to ignore.

Validate Password Component

If you choose to accept the Validate Password Policy, you will be asked to provide the level of complexity. Choose the level and press enter to continue with the configuration

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Now, you will set password for MySQL root user. The password should contain an uppercase letter, lowercase letter, a number and a special character.

Please set the password for root here.

New password: A@VeRy@[email protected]

Re-enter new password: A@VeRy@[email protected]

You will have to remove the anonymous users, disallow remote root login, remove test databases and reload privileges tables to apply the changes.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

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? (Press y|Y for Yes, any other key for No) : y 

By default, 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

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...

 - Removing privileges on test database...

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

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done!

MySQL 8 has been installed and running on FreeBSD 12.

Verifying The Installation

To verify the installation, you can login as root and check the database version using the following command:

mysqladmin -u root -p version
Enter password: 
mysqladmin  Ver 8.0.16 for FreeBSD12.0 on amd64 (Source distribution)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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

Server version		8.0.16
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/tmp/mysql.sock
Uptime:			28 min 39 sec

Threads: 2  Questions: 15  Slow queries: 1  Opens: 162  Flush tables: 3  Open tables: 63  Queries per second avg: 0.008

Congartulations, you have successfully installed and configured MySQL 8 on your FreeBSD System.