For the complete documentation index, see llms.txt. This page is also available as Markdown.

35.4 MySQL

MySQL is an open-source relational database management system (Relational Database Management System, RDBMS) primarily developed by Oracle Corporation.

MySQL 9.7 is the latest Long Term Support (LTS) version, and MySQL 8.4 is the previous Long Term Support (LTS) version.

Installing MySQL 8.4 LTS

Install using pkg:

# pkg install mysql84-server

Or install using Ports:

# cd /usr/ports/databases/mysql84-server/
# make install clean

View the post-installation instructions:

# pkg info -D mysql84-server

Installing MySQL 9.7 LTS

Install using pkg:

# pkg install mysql97-server

Or install using Ports:

# cd /usr/ports/databases/mysql97-server/
# make install clean

View the post-installation instructions:

Starting the Service

After installation is complete, you need to start the MySQL service before you can use it.

Set the MySQL service to start on boot:

Start the MySQL service immediately:

Logging In

After the service starts, you can log in to MySQL using the command-line client (which will be automatically installed as a dependency). According to the installation instructions, the default password for MySQL 8.4 and 9.7 is empty; just press Enter when prompted for a password.

Log in to the MySQL server as the root user, and enter the password when prompted:

Changing the Password

For database security, it is recommended to change the root user password immediately after the first login. The following command sets the root user password of the database to SecurePass123!; the change takes effect immediately, and then exits MySQL.

Tip

The SecurePass123! in the above example is a placeholder and needs to be replaced with an actual value.

Log in again:

MySQL Configuration File

The MySQL configuration file structure is as follows.

If you need to further configure MySQL, you can modify its configuration file. The configuration file can adjust various database parameters, such as memory usage, number of connections, etc.

The default MySQL configuration file template is located at /usr/local/etc/mysql/my.cnf.sample, and the actual default configuration file is located at /usr/local/etc/mysql/my.cnf (default content is empty).

Copy the MySQL sample configuration file to the active configuration file:

Then modify the /usr/local/etc/mysql/my.cnf file as needed.

If you need to use a custom configuration file path, you can write the following in the /etc/rc.conf file:

Last updated