MySQL 8 is one of the most widely deployed relational database systems in the world, offering robust performance, strong security features, and broad application compatibility. On RHEL 8, MySQL is not included in the default AppStream modules, so you must add the official MySQL community repository before installing. This guide walks through adding the MySQL 8.0 repository, disabling the conflicting AppStream module, installing the server, and securing your installation. By the end you will have a running, firewall-configured MySQL 8 instance ready for production use.
Prerequisites
- A server running RHEL 8 (or a compatible derivative such as AlmaLinux 8 or Rocky Linux 8)
- A non-root user with
sudoprivileges, or direct root access dnfand internet access to reach the MySQL CDN and RHEL repositoriesfirewalldrunning if you intend to allow remote MySQL connections
Step 1 — Add the MySQL 8.0 Community Repository
MySQL is not part of the RHEL 8 AppStream, so you must register the official MySQL repository RPM. This package installs the repository definition files under /etc/yum.repos.d/ and imports the MySQL GPG signing key.
sudo dnf install -y https://dev.mysql.com/get/mysql80-community-release-el8-9.noarch.rpm
After the command completes, verify the new repository is visible:
dnf repolist | grep mysql
You should see entries such as mysql80-community and mysql-connectors-community listed as enabled.
Step 2 — Disable the AppStream MySQL Module
RHEL 8’s AppStream includes a mysql module that, if left enabled, will conflict with the community packages and prevent installation. Disable it before proceeding so that dnf resolves all MySQL dependencies from the community repository instead.
sudo dnf module disable -y mysql
Confirm the module is now disabled:
dnf module list mysql
The status column for the mysql module should show disabled.
Step 3 — Install MySQL Community Server
With the community repository active and the AppStream module disabled, install the MySQL server package and all required dependencies in a single command.
sudo dnf install -y mysql-community-server
Once the installation finishes, enable and start the mysqld service so that it also launches automatically on future reboots:
sudo systemctl enable --now mysqld
Verify that the service is active:
sudo systemctl status mysqld
Step 4 — Retrieve the Temporary Root Password
On first startup, MySQL generates a temporary password for the root account and writes it to the error log. You must use this password to authenticate during the initial secure installation step.
sudo grep 'temporary password' /var/log/mysqld.log
The output will resemble:
2024-01-15T10:23:45.123456Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Ab1!xY3#pQrZ
Copy the password at the end of the line; you will need it in the next step.
Step 5 — Secure the MySQL Installation
Run the mysql_secure_installation script, which guides you through setting a strong root password, removing anonymous users, disabling remote root login, and dropping the test database. These steps are critical before exposing MySQL to any network.
sudo mysql_secure_installation
When prompted for the current password, enter the temporary password you retrieved in Step 4. The script will then ask you to set a new password that satisfies MySQL’s default validate_password plugin requirements (uppercase, lowercase, digit, special character, minimum 8 characters). Answer Y to all remaining prompts to apply all recommended security hardening settings.
Step 6 — Configure the Firewall for Remote Access
If you need to allow clients on other hosts to connect to MySQL, open port 3306 in firewalld. If MySQL will only be accessed locally, skip this step to minimise your attack surface.
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
You can now test a remote connection from another machine:
mysql -u root -p -h
For production environments, consider creating a dedicated application user with limited privileges rather than connecting as root.
Conclusion
You have successfully installed MySQL 8 on RHEL 8 by adding the official community repository, disabling the conflicting AppStream module, installing and starting the mysqld service, and hardening the installation with mysql_secure_installation. Your MySQL 8 instance is now secured and ready to host databases for your applications.
Next steps: How to Create and Manage MySQL Databases and Users on RHEL 8, How to Configure MySQL Replication on RHEL 8, and How to Backup and Restore MySQL Databases with mysqldump on RHEL 8.