How to Install MySQL 8.0 on Rocky Linux 8
Introduction
MySQL 8.0 is the latest stable version of MySQL, a popular open-source relational database management system.
It is widely used for modern applications, websites, and cloud platforms.
In this guide, we will learn how to install and configure MySQL 8.0 on Rocky Linux 8 step by step.
Step 1: Update Your Rocky Linux System
Before installing, always update your system packages to the latest version.
sudo dnf update -y
sudo reboot
Step 2: Add the MySQL 8.0 Repository
Rocky Linux provides MariaDB by default. To install the official MySQL 8.0, we need to enable the MySQL community repository.
sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm -y
After installation, verify repository is added:
dnf repolist enabled | grep mysql
Step 3: Install MySQL 8.0 Server
Now install the MySQL 8.0 server package.
sudo dnf install mysql-community-server -y
Step 4: Start and Enable MySQL Service
Start MySQL and enable it to run automatically on system boot.
sudo systemctl start mysqld
sudo systemctl enable mysqld
Check status:
systemctl status mysqld
Step 5: Secure MySQL Installation
MySQL creates a temporary root password during first installation.
You can find it in the log file:
sudo grep 'temporary password' /var/log/mysqld.log
Then run the security script:
sudo mysql_secure_installation
This will ask you to set a new root password, remove anonymous users, disable remote root login, and remove test databases.
Step 6: Login to MySQL
Now login using the root account and the password you set:
mysql -u root -p
Once logged in, you can check the MySQL version:
SELECT VERSION();
Step 7: Enable Firewall for MySQL (Optional)
If you want to allow remote MySQL connections, open port 3306
in firewall.
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
Step 8: Create a Database and User (Optional)
Inside MySQL shell, create a new database and user.
CREATE DATABASE testdb;
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'StrongPassword123';
GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost';
FLUSH PRIVILEGES;
Conclusion
You have successfully installed MySQL 8.0 on Rocky Linux 8.
From here, you can create databases, manage users, and connect applications like WordPress, PHP, and Python to your MySQL server.
This setup is suitable for both practice environments and production servers.