Sometimes it can not be avoided. MySQL needs to be installed for one reason or another. This post covers installing MySQL on FreeBSD.

Software Versions

$ date -u "+%Y-%m-%d %H:%M:%S +0000"
2016-07-14 01:23:55 +0000
$ uname -vm
FreeBSD 11.0-ALPHA6 #0 r302384: Thu Jul  7 22:40:47 JST 2016  amd64
$ mysqladmin -u root -p version
mysqladmin  Ver 8.42 Distrib 5.7.13, for FreeBSD11.0 on amd64

Server version		5.7.13-log
Protocol version	10
*snipped some output*


Install using packages.

pkg install mysql57-server mysql57-client

Alternatively, install using ports.

portmaster databases/mysql57-server databases/mysql57-client

Enable MySQL in rc.conf.

/etc/rc.conf partial listing


Start MySQL from the command line. Note that the above rc.conf line will automatically start MySQL when the machine boots. Note that the default location for my.conf is /usr/local/etc/mysql/my.cnf.

service mysql-server start

Note that if /var/db/mysql exists and is not empty, mysql-server will fail to start the first time. Backup or remove this directory if you need to. See this blog post to track down other errors when starting mysql-server for the first time.

# Backup
mv /var/db/mysql /var/db/mysql.old

# Remove
rm -rf /var/db/mysql

Reset the password. Note that the initial password is stored in $HOME/.mysql_secret. For example, if you use mysql -u root -p the initial password is stored in /root/.mysql_secret.

mysql -u root -p -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';"

If upgrading from an earlier version, run mysql_upgrade. Note that the command below upgrades as the root user.

mysql_upgrade -u root -p

Uninstall with pkg.

pkg delete mysql57-server mysql57-client

Uninstall with portmaster.

portmaster -e databases/mysql57-server databases/mysql57-client