Install MySQL 8 on FreeBSD 12


In this tutorial, we are going to learn how to install MySQL 8 on FreeBSD 12. MySQL 8 can be installed on FreeBSD 12 using Ports collection or using the MySQL generic Unix binaries. This guide focuses on using the FreeBSD 12 Ports collection.

Install MySQL 8 on FreeBSD 12

To compile an application/port using Ports Collection, you should first install the Ports Collection if they were not installed with the OS. The Ports Collection is stored as a subdirectory of /usr/ports by default. The specific Ports collection for MySQL database server and client 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

If the Ports Collection are not installed, see the section of installing Ports Collection in the link below.

Install or Uninstall Software on FreeBSD 12 using Ports Collection

Once you have installed Ports Collection, proceed to install MySQL 8.

Install MySQL 8 server on FreeBSD 12

Navigate to MySQL Ports subdirectory and run make install to install MySQL 8 server.

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

The clean option ensures that all the temporary files generated during compilation are removed from the system to save on disk space.

Note that compilation may take sometime depending on how powerful your system is.

At the end of compilation, if all goes well, you will see such an output.


      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:

Speaking of security, FreeBSD pkg includes a built-in auditing mechanism for determining if there are any known vulnerabilities for the software installed on 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, run the command below to add MySQL service to /etc/rc.conf.

sysrc mysql_enable=yes

Next, start MySQL

service mysql-server start

Check the service status

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

Securing MySQL

To run initial MySQL security, run the mysql_secure_installation script.


When run, the script prompts you on whether to enforce password complexity through the use of validate_password_policy. Type Y and press Enter to enable or any other key to ignore.

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

If you accept to enable the validate password plugin, you will be prompted to choose the level of complexity, with three levels provided. Choose the level and press ENTER to proceed.

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

Next, set the MySQL root user password.

Please set the password for root here.

New password: Str0ng@123P@SS

Re-enter new password: Str0ng@123P@SS

Remove 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 is now installed and running on FreeBSD 12. To verify the installation, you can login as root and check the database version.

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

Well done. You have successfully installed MySQL 8 on FreeBSD 12.

Related tutorial;

Install MySQL 8 on Debian 9

Install MySQL 8 on Fedora 30/Fedora 29

Install LAMP Stack on Fedora 30

How To Install LAMP (Linux, Apache, MySQL, PHP) Stack on Fedora 28/29

Install MariaDB 10.3 on CentOS 7

Install MariaDB 10.3 on Fedora 30

Install phpMyAdmin with Apache on Fedora 30


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Jay Decrame
Linux Certified Engineer, Technology and Linux/Unix enthusiast.

1 thought on “Install MySQL 8 on FreeBSD 12”

Leave a Comment