How To Install MySQL on Rocky Linux 8

In this article, we want to teach you How To Install MySQL on Rocky Linux 8.

Rocky Linux comes with MySQL in its AppStream, but it is not in the latest release. In this guide, you learn to install MySQL in the latest release on Rocky Linux 8.

MySQL is an open-source relational database management system (DBMS). It is developed, supported, and distributed by Oracle Corporation and it has a vibrant community around it. Some of the key MySQL features include:

  • Portability: MySQL works on many different platforms and is configured using CMake
  • Works on top of various storage engines, with the option to add new engines relatively easily to provide a SQL interface to an in-house database
  • In-memory hash tables, which are used as temporary tables
  • Many data types, including JSON and spatial
  • Full operator and function support in the SELECT list and WHERE clause of queries

How To Install MySQL on Rocky Linux 8

Before you start to install MySQL on your server, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Rocky Linux 8.

Now follow the steps below to complete this guide.

We will show you to install MySQL from AppStream and its community edition.

Install MySQL from AppStream on Rocky Linux 8

First, you need to update your local package index with the command below:

sudo dnf update -y

Then, check the MySQL versions that are available in the Rocky Linux repository with the command below:

sudo dnf module list mysql

In your output you will see:

Last metadata expiration check: 0:18:31 ago on Thu 24 Feb 2022 02:33:13 AM EST.
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
mysql 8.0 [d] client, server [d] MySQL Module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

As you can see the latest available version of MySQL is 8.0. You can use the command below to enable MySQL 8.0 module on Rocky Linux 8:

sudo dnf module enable mysql:8.0 -y

Next, use the following command to install it:

sudo dnf install mysql

Verify your installation by checking its version:

mysql --version
mysql  Ver 8.0.26 for Linux on x86_64 (Source distribution)

Now use the command below to enable MySQL on Rocky Linux 8:

sudo systemctl enable mysqld --now

This will activate MySQL in your current session, and on future systems, restarts automatically.

Install MySQL Community Edition on Rocky Linux 8

The other way to install the latest release of MySQL on your server is using the MySQL RPM.

First, you need to import the official MySQL Community RPM from its official downloads page with the command below:

sudo rpm -ivh

Then, verify that the repository is added successfully to your server with the following command:

dnf repolist all | grep mysql | grep enabled
mysql-connectors-community MySQL Connectors Community enabled
mysql-tools-community MySQL Tools Community enabled
mysql80-community MySQL 8.0 Community Server enabled

Now use the following command to disable the App Stream version and enable the community edition:

sudo dnf install --disablerepo=appstream mysql-community-server

Verify your MySQL installation by checking its version:

mysql --version
mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)

Enable your MySQL service on Rocky Linux 8:

sudo systemctl enable mysqld --now

This will activate MySQL in your current session, and on future systems, restarts automatically.

Also, you can check your MySQL service is active and running on your server with the command below:

systemctl status mysqld

In your output you will see:

mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset>
Active: active (running) since Thu 2022-02-24 03:10:42 EST; 4min 3s ago
Docs: man:mysqld(8)
Process: 91202 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/>
Main PID: 91291 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 11409)
Memory: 484.8M
CGroup: /system.slice/mysqld.service
└─91291 /usr/sbin/mysqld

Now that you have MySQL service installed on your Rocky Linux 8, you can secure it by running the security script.

Secure MySQL with Security Script

At this point, you can secure your MySQL service by running a single security script.

By default, MySQL generates a default root password for you when starting the service the first time. The password is stored in the MySQL log file ‘/var/log/mysqld.log’.

To display the default root password, you can use the following command:

grep 'temporary' /var/log/mysqld.log

You will get similar output like this:

A temporary password is generated for root@localhost: o;j1.(DGPsDK

Then, run the command below to secure your MySQL service on Rocky Linux 8 and change your default root password:

sudo mysql_secure_installation

You will be asked to enter the root password. You should enter the default MySQL root password.

Then, you will get the following message:

The existing password for the user account root has expired. Please set a new password. 
New password: <---- SET NEW PASSWORD 
Re-enter new password: <---- RE-ENTER NEW PASSWORD

Here you need to enter your new password and press enter.

After that, you will be asked to change the root password, SKIP IF YOU ALREADY JUST SET.

From here press Y to continue.

Now you can log in to your MySQL shell with the command below and the new password you have generated:

sudo mysql -u root -p

You will see your MySQL console:

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


If you no longer wish to use the MySQL database and want to remove it in full, execute the following command:

sudo dnf remove mysqld


At this point, you learn to Install MySQL on Rocky Linux 8.

Hope you enjoy it.

You may be interested in these articles on the orcacore website:

How To Install WordPress on Rocky Linux 8.

How To Set up PHP 8.1 on Rocky Linux 8.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!