Guides 11792 Published by

This tutorial walks you through installing a genuine MySQL 8.0 server on CentOS 9 Stream by first adding Oracle’s official mysql80-community-release RPM, which creates the necessary repo files under /etc/yum.repos.d/. It then disables the distro‑provided MySQL module to prevent accidental MariaDB installation, installs mysql-community-server, starts and enables the service, and extracts the autogenerated temporary root password from the MySQL error log. Afterward you run mysql_secure_installation to set a permanent root password, remove insecure defaults, and optionally configure SELinux contexts if you use custom data directories. A final verification step (mysql -u root -p -e "SELECT VERSION();") confirms that version 8.0 is running correctly.



Install MySQL 8.0 on CentOS 9 Stream

What you’ll get out of this

You’ll have a clean, production‑ready MySQL 8.0 server running on CentOS 9 Stream without pulling in the whole MariaDB stack by accident. I’ll walk through adding the official repo, installing the packages, and locking down the default root password.

Add the official MySQL repository

CentOS 9 Stream doesn’t ship MySQL 8 in its base repos; it only offers MariaDB. The easiest way to get the real thing is to pull the RPM from Oracle’s site.

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

The package drops a new file under /etc/yum.repos.d/ that points to MySQL’s own mirrors. This step matters because without the right repo you’ll end up installing MariaDB and spend an hour figuring out why mysql --version shows 10.x.

Disable the default module stream

CentOS 9 Stream ships a “module” for MySQL that defaults to version 8.0 but can be overridden by other streams. To avoid conflicts, turn it off:

sudo dnf -qy module disable mysql

If you skip this, DNF might try to satisfy dependencies with the stream’s packages and you’ll get a half‑installed mess.

Install MySQL server

Now pull in the actual server and client binaries:

sudo dnf install -y mysql-community-server

During installation DNF pulls in all required libraries from Oracle’s repo, not the distro’s older copies. I’ve seen people run dnf install mysql on CentOS 9 and end up with a MariaDB server that refuses to start after a reboot – avoid that pain.

Start and enable the service

sudo systemctl start mysqld
sudo systemctl enable mysqld

Starting it right away lets you grab the temporary root password that MySQL generates on first launch. It’s written to the error log:

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

Copy that string; you’ll need it for the secure‑setup step.

Run mysql_secure_installation

MySQL ships a helper script that does three things: set a new root password, remove anonymous users, disable remote root login, and delete the test database. It’s not optional if you plan to expose the server beyond localhost.

sudo mysql_secure_installation

When prompted for the current password, paste the temporary one from the log. Then choose a strong password of your own. The script will ask whether to enable the VALIDATE PASSWORD plugin – I usually say “no” unless my policy demands it; the extra complexity often just scares newcomers.

Verify the installation

A quick check that everything is working:

mysql -u root -p -e "SELECT VERSION();"

You should see something like 8.0.36. If you get an error about socket files, double‑check that /var/run/mysqld exists and has proper permissions – a mis‑configured SELinux policy can block the socket creation.

Optional: tweak SELinux (only if you really need it)

CentOS 9 Stream runs SELinux in enforcing mode by default. MySQL works out of the box, but if you mount data directories on non‑standard paths you may see “permission denied” errors. The fix is a one‑liner:

sudo semanage fcontext -a -t mysqld_db_t "/my/custom/path(/.*)?"
sudo restorecon -R /my/custom/path

If you never move the datadir, skip this whole section – it’s just noise.

That’s it. You now have a clean MySQL 8.0 server ready for your apps.