Menu

How to Install MySQL 8.4 LTS on Red Hat Enterprise Linux 9

Install MySQL 8.4 LTS on RHEL 9.6 or later from its AppStream module, then initialize the cluster and start the service.

Posted on By Updated on
On this page

MySQL 8 is a major MySQL series that includes features such as common table expressions, window functions, atomic DDL, and JSON functions.

In this tutorial, we will install the community version of MySQL 8 on RHEL 9 from the default repositories. We will also look at how to manage the MySQL service, secure the installation, create a database and tables to verify the installation.

RHEL 9.6 and later provide the mysql:8.4 AppStream. This procedure selects that stream explicitly; if you use an earlier RHEL 9 minor release, update it first. See Red Hat’s MySQL installation instructions.

Prerequisites

Before starting, make sure you have:

  • A server running Red Hat Enterprise Linux 9 with root access or a non-root user with sudo privileges.
  • Internet connectivity to download MySQL packages.

Step 1 - Install MySQL 8.4 LTS

Install the MySQL 8.4 server module:

sudo dnf module install mysql:8.4/server

This selects the MySQL 8.4 stream and its server profile.

Step 2 - Verify the Installed Version

Check the installed MySQL version:

mysql --version

Step 3 - Start MySQL Service

Once installed, we need to start the MySQL service for initial setup:

sudo systemctl start mysqld

This will start the mysqld daemon process in the background.

Step 4 - Secure the MySQL Installation

It is highly recommended to run the mysql_secure_installation script to improve the security of your MySQL installation:

sudo mysql_secure_installation
  • Set a strong root password
  • Remove anonymous user accounts
  • Disable remote root login
  • Remove test database
  • Reload privileges

Answer Yes to all the questions asked by the script to perform the steps above.

Step 5 - Manage MySQL Service

The main MySQL commands to manage the service are:

sudo systemctl start mysqld    # Start MySQL
sudo systemctl stop mysqld     # Stop MySQL
sudo systemctl restart mysqld  # Restart MySQL
sudo systemctl status mysqld   # Check status

This allows you to start, stop, restart and check status of the MySQL service.

Step 6 - Create a Dedicated MySQL User

For improved security, we should create a dedicated MySQL user for applications instead of using the root user directly:

-- Run as an administrator before logging in with the application account.
CREATE DATABASE IF NOT EXISTS mytestdb;
-- MySQL 8.0.18+ returns a generated password; save it securely for the connection test.
CREATE USER 'myuser'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
-- CREATE is included for the sample table; use a separate migration account for schema changes in production.
GRANT CREATE, SELECT, INSERT, UPDATE, DELETE ON mytestdb.* TO 'myuser'@'localhost';

Choose the account name you need, then save the generated password shown by MySQL in a secure secret store; do not reuse it or commit it to application code.

Step 7 - Test MySQL Connection

As a test, connect to the MySQL server using the new user account created:

mysql -u myuser -p
Enter password:

This will connect you to the MySQL shell to run queries.

Step 8 - Create a Sample Table

The administrator created mytestdb in the previous step. Create a sample table in it:

USE mytestdb;

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

We now have MySQL 8 installed and ready to be used!

Conclusion

In this detailed tutorial, we went through the steps to install MySQL community server 8 on Red Hat Enterprise Linux 9. We also looked at starting, stopping and checking status of the MySQL service. Finally, we tested creating a dedicated user, new database and tables to validate the installation.

You can now use this MySQL server for your web or server applications that require a relational database to store and manage data.

If you want to learn more about MySQL, please use our MySQL tutorials and MySQL Reference.