Install MySQL on RHEL9 or CentOS

Install MySQL on RHEL9 or CentOS

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:

sudo dnf update -y

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:

sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm -y

Enable the MySQL 8.0 repository:

sudo dnf module disable mysql -y sudo dnf config-manager --enable mysql80-community

Step 3: Install MySQL Server

sudo dnf install mysql-community-server -y

This installs the MySQL server, client, and common tools.

Step 4: Start and Enable MySQL Service

sudo systemctl start mysqld sudo systemctl enable mysqld

You can verify the service is running:

sudo systemctl status mysqld

Step 5: Get Temporary MySQL Root Password

After installation, MySQL generates a temporary root password.

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

Copy the temporary password shown in the output.

Step 6: Secure MySQL Installation

Run the security script:

sudo mysql_secure_installation

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

mysql -u root -p

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:

sudo firewall-cmd --permanent --add-service=mysql sudo firewall-cmd --reload

Conclusion

You've successfully installed and secured MySQL on RHEL 9 / CentOS Stream 9. You're now ready to create databases, users, and applications.

Souy Soeng

Souy Soeng

Hi there šŸ‘‹, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
šŸ‘Æ I’m looking to collaborate on open-source PHP & JavaScript projects
šŸ’¬ Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
close