Guide On How To Install MySQL On FreeBSD

Guide On How To Install MySQL On FreeBSD 2017-08-04T09:47:52+02:00

A Step By Step Guide On How To Install A MySQL Server On FreeBSD
This will show you how to install a MySQL server from ports. At the time of writing this version of MySQL for FreeBSD is 5.7.18. If there are significant changes in future releases I will off cause update the guide accordingly when I get the time.

Before we start please note that the initial password for MySQL 5.7x is saved in /root/.mysql_secret ie. so when using “mysql -u root -p” for the first time use that password. Also worth noticing is the fact that the default location for the MySQL configuration file my.cnf has changed from “/var/db/mysql/my.cnf” to “/usr/local/etc/mysql/my.cnf”. Right then let’s install MySQL.

cd /usr/ports/databases/mysql57-server && make install clean BATCH=yes

Once the installation is done copy the “stock” MySQL configuration file to its propper location and set some propper permissions as well.

cp /usr/local/etc/mysql/my.cnf.sample /usr/local/etc/mysql/my.cnf
chown mysql:mysql /usr/local/etc/mysql/my.cnf

My personal my.cnf file has the following extra options added to it, just wanted to show you some possibilities.




Enable MySQL to startup after boot by adding the following to /etc/rc.conf and then either reboot or start MySQL manually.


MySQL now creates a random password that resides in /root/.mysql_secret.
If /root/.mysql_secret does not exist it’s probably because MySQL isn’t running. The file is created during the initial startup of MySQL.

Hardening MySQL. I strongly advice doing this right after your MySQL server has started. MySQL. You can launch it like this. Btw you can run this as many times as you like in case you want to change something.


When you are done with the above please consider changing the mysql root passwd. We will use an example where the /root/.mysql_secret password is “abc” and we would like to set the password to “123456”. The command for doing this would be.

mysqladmin -u root -p'abc' password '123456'

Once done delete /root/.mysql_secret

rm /root/.mysql_secret

Finally check if things are working as intended.

ps -waux |grep "mysql"

And we are done here.

Spell checkers don’t – Grammar checkers don’t either.