MySQL 8.0 on Rocky Linux EL9 or EL8
You want the newest MySQL 8.0, not a half‑baked copy from the distro repos.
This article walks you through getting it up and running on both Rocky Linux 9 and 8 in under ten minutes—no source‑compile headaches or mysterious dependency hell.
1. Clean the ground floor
If MariaDB is lurking around, it can silently steal the mysql port or choke your mysqld.
sudo dnf list installed | grep -i mariadb
If anything shows up, drop it:
sudo dnf remove mariadb-server mariadb-client –y
Removing MariaDB is cheap and prevents future port collisions.
2. Drop the official MySQL community repo
Rocky Linux is RHEL‑based, so the MySQL Community Edition keeps a separate RPM for each major release:
For EL9:
sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm –y
For EL8:
sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm –y
Why this matters: The RPM installs a custom YUM repo file under /etc/yum.repos.d/.
Without it, you’d be stuck with the old 5.7 shipped by default.
3. Install MySQL Server
sudo dnf install mysql-community-server –y
The community package pulls in all dependencies (InnoDB engine, SSL libs, etc.).
If you prefer a minimal footprint, swap mysql-community-server for mysql-community-server-core, but keep the full stack if you need replication or GTIDs.
4. Open the firewall and tweak SELinux
MySQL listens on TCP 3306 by default. Rocky’s firewalld blocks it unless we ask explicitly:
sudo firewall-cmd --add-service=mysql --permanent sudo firewall-cmd --reload
SELinux can also bite; the default mysqld boolean is off for outbound network connections, which will break remote clients:
sudo setsebool -P mysqld_can_network_connect_db on
A real‑world hiccup I ran into last month: after a kernel upgrade my MySQL refused to accept external connections because SELinux denied the bind. Turning that boolean solved it instantly.
5. Start and enable the service
sudo systemctl start mysqld sudo systemctl enable mysqld
Verify with:
systemctl status mysqld
If you see Active: active (running) you’re good to go.
6. Secure the installation
Running the classic MySQL secure‑install script is worth every minute:
sudo mysql_secure_installation
You’ll be prompted for the root password, removal of anonymous users, disallowing remote root login, and dropping the test database.
I’ve found that skipping the “remove test db” step keeps a handy playground during development; just remember to purge it before going live.
7. Optional tweaks
- Change the default character set – edit /etc/my.cnf.d/mysql-community.conf:
[mysqld] character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci
Then restart mysqld.
- Set a custom data directory – add datadir=/my/custom/path under [mysqld], move the existing /var/lib/mysql to that location, and adjust ownership (chown -R mysql:mysql /my/custom/path).
Useful if you’re running out of space on /dev/sda.
- Enable slow‑query logging for performance tuning:
[mysqld] slow_query_log = ON long_query_time = 1
Remember to create the log file and set permissions.
That’s it. You now have MySQL 8.0 humming on Rocky Linux EL9 or EL8, ready for anything from a hobby project to a production stack.