This page looks best with JavaScript enabled

MySQL Server on FreeBSD

 ·  🎃 kr0m

In this article, I will explain how to install a MySQL server on FreeBSD and the initial configuration to perform.

Check which versions of MySQL are available:

pkg search mysql

mysql55-client-5.5.62_3        Multithreaded SQL database (client)
mysql55-server-5.5.62_3        Multithreaded SQL database (server)
mysql56-client-5.6.51          Multithreaded SQL database (client)
mysql56-server-5.6.51          Multithreaded SQL database (server)
mysql57-client-5.7.34          Multithreaded SQL database (client)
mysql57-server-5.7.34          Multithreaded SQL database (server)
mysql80-client-8.0.25_1        Multithreaded SQL database (client)
mysql80-server-8.0.25_1        Multithreaded SQL database (server)

Install the latest available version:

pkg install mysql80-server-8.0.25_1

Enable the service:

sysrc mysql_enable=YES

Start the service:

service mysql-server start

Access the MySQL CLI:


The root user has NO password, so we assign one:

ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'PASSWORD';

From now on, it will ask for a password to access:

mysql -uroot -p’PASSWORD'

If we don’t want to indicate the user/password every time, we can configure it in the following file:

vi .my.cnf

user = root
password = PASSWORD

Limit access to this file:

chmod 600 .my.cnf

If necessary, we must also configure the relevant firewall rules for MySQL.
If any adjustments need to be made to MySQL, we must edit the configuration file /usr/local/etc/mysql/my.cnf.

If you liked the article, you can treat me to a RedBull here