How to Install MySQL on RHEL 9 / CentOS Stream 9
MySQL is a powerful open-source relational database. This guide walks you through installing the latest MySQL on Red Hat Enterprise Linux 9 (RHEL 9) or CentOS Stream 9.
Step 1: Update Your System
Before installing anything, update your package index:
Step 2: Add the MySQL Yum Repository
RHEL/CentOS 9 does not ship with the latest MySQL. You’ll need to download the official MySQL repository package.
Download and install the MySQL repo:
Enable the MySQL 8.0 repository:
Step 3: Install MySQL Server
This installs the MySQL server, client, and common tools.
Step 4: Start and Enable MySQL Service
You can verify the service is running:
Step 5: Get Temporary MySQL Root Password
After installation, MySQL generates a temporary root password.
Copy the temporary password shown in the output.
Step 6: Secure MySQL Installation
Run the security script:
You'll be prompted to:
-
Enter the temporary root password
-
Set a new strong root password
-
Remove anonymous users
-
Disallow remote root login
-
Remove test databases
-
Reload privilege tables
Answer Y
(yes) for recommended options.
Step 7: Log Into MySQL
Enter the new root password you just set to access the MySQL shell.
Optional: Enable Firewall Access (Remote Access)
If your server uses a firewall and you want to allow remote MySQL access:
Conclusion
You've successfully installed and secured MySQL on RHEL 9 / CentOS Stream 9. You're now ready to create databases, users, and applications.