Menu

How to Install MySQL 8.4 on FreeBSD

Install MySQL 8.4 LTS on a supported FreeBSD release, initialize a secure root account, enable the service, and create a restricted application user.

Posted on By Updated on
On this page

This guide installs MySQL 8.4 LTS from the FreeBSD package repository. MySQL 8.0 reached end of life in April 2026; FreeBSD Ports changed its default MySQL version to 8.4 in March 2026. Use a FreeBSD release that is currently supported by the FreeBSD Security Officer; FreeBSD 12 is no longer supported. See the MySQL 8.0 release notes and the FreeBSD Ports version update notices.

Install the MySQL 8.4 package

As root or through sudo, refresh the package catalog and install the MySQL 8.4 server:

pkg update
pkg install mysql84-server

The FreeBSD port installs the mysql operating-system account and the mysql-server service. For the package definition, see the FreeBSD Ports mysql84-server directory.

Initialize MySQL with a temporary root password

For the default FreeBSD package paths, initialize the empty data directory with MySQL’s secure initialization mode:

/usr/local/libexec/mysqld --initialize \
  --user=mysql \
  --basedir=/usr/local \
  --datadir=/var/db/mysql

Save the temporary password printed by the command or written to the MySQL error log. --initialize creates a random password and marks it expired, so replace it after the first login. Do not use --initialize-insecure on a server that can accept network connections. See MySQL’s data-directory initialization guide.

Enable and start the service:

sysrc mysql_enable="YES"
service mysql-server start

Connect interactively as the initial root account and enter the temporary password when prompted:

mysql --user=root --password

At the MySQL prompt, let the server generate a permanent root password:

ALTER USER 'root'@'localhost' IDENTIFIED BY RANDOM PASSWORD;

MySQL displays the generated password once. Save it in a password manager before closing the session. IDENTIFIED BY RANDOM PASSWORD is supported from MySQL 8.0.18; see the ALTER USER reference.

Create a database and restricted application account

Use the administrative session to create the database and its table, then give the application account only the row operations used by this example:

CREATE DATABASE mytestdb;

CREATE TABLE mytestdb.users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(50),
  email VARCHAR(50)
);

CREATE USER 'myapp'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
GRANT SELECT, INSERT, UPDATE, DELETE ON mytestdb.* TO 'myapp'@'localhost';

Save the generated application password securely. The account can read and modify rows in mytestdb, but cannot create or alter tables. Grant schema-management privileges separately to a migration account if the application needs them.

Test the application account by connecting to the database and entering its generated password at the prompt:

mysql --user=myapp --password --database=mytestdb

Then run:

SELECT CURRENT_USER(), DATABASE();
SHOW TABLES;

For more MySQL administration and SQL guides, see the MySQL tutorial and SQL and database tools.