MySQL is the world’s most widely deployed open-source relational database, powering WordPress, Magento, Drupal, and countless custom web applications. RHEL 9’s AppStream does not include MySQL directly — it ships MariaDB as the default MySQL-compatible database. To install the latest MySQL 8.4 LTS (or MySQL 8.0), you must add the official MySQL Community repository from MySQL’s yum repository. MySQL 8.x includes improvements over MySQL 5.7 including roles-based access control, invisible indexes, window functions, better JSON support, and the caching_sha2_password authentication plugin as the default. This guide covers adding the MySQL repository, installing MySQL 8 on RHEL 9, securing the installation, creating a database and user, configuring remote access, and enabling automatic backups.
Prerequisites
- RHEL 9 with sudo/root access
- Internet access for package download
Step 1 — Add the MySQL Community Repository
# Download and install the MySQL repo RPM
dnf install -y https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
# Verify the repo was added
dnf repolist | grep mysql
# Install MySQL 8.4 Community Server
dnf install -y mysql-community-server
Step 2 — Start and Enable MySQL
systemctl enable --now mysqld
systemctl status mysqld
# Get the temporary root password generated at first start
grep 'temporary password' /var/log/mysqld.log
Step 3 — Secure MySQL Installation
# Run the secure installation wizard (uses the temporary password from the log)
mysql_secure_installation
# Wizard prompts:
# - Change root password? Yes (set a strong password)
# - Remove anonymous users? Yes
# - Disallow root login remotely? Yes
# - Remove test database? Yes
# - Reload privilege tables? Yes
Step 4 — Log In and Create a Database
mysql -u root -p
-- Inside MySQL shell
SHOW VARIABLES LIKE 'version';
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON myapp.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;
SHOW DATABASES;
EXIT;
Step 5 — Configure MySQL for Performance
# /etc/my.cnf.d/mysql-custom.cnf
[mysqld]
# InnoDB buffer pool — set to 70% of available RAM
innodb_buffer_pool_size = 1G
# Slow query log for performance analysis
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
# Binary log for replication and point-in-time recovery
log_bin = /var/lib/mysql/mysql-bin
expire_logs_days = 7
max_binlog_size = 100M
# Character set
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
mkdir -p /var/log/mysql && chown mysql:mysql /var/log/mysql
systemctl restart mysqld
Step 6 — Allow Remote Access (Optional)
# Allow MySQL port through the firewall
firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload
# Create a remote user (restrict to specific IP for security)
mysql -u root -p -e "CREATE USER 'myapp_user'@'192.168.1.100' IDENTIFIED BY 'StrongPassword123!'; GRANT ALL PRIVILEGES ON myapp.* TO 'myapp_user'@'192.168.1.100'; FLUSH PRIVILEGES;"
Step 7 — Automated Daily Backup
# /etc/cron.d/mysql-backup
0 2 * * * root mysqldump -u root -pStrongPassword myapp | gzip > /var/backups/myapp-$(date +%Y%m%d).sql.gz
# Retain 7 days of backups
0 3 * * * root find /var/backups/ -name "myapp-*.sql.gz" -mtime +7 -delete
Conclusion
MySQL 8 on RHEL 9 provides a production-grade relational database with modern authentication, improved JSON support, and role-based access control. The MySQL Community repository gives access to the latest 8.x releases directly from Oracle. Configure InnoDB buffer pool sizing, enable slow query logging, and set up daily mysqldump backups for a complete, production-ready installation.
Next steps: How to Install MariaDB on RHEL 9, How to Configure MySQL Primary-Replica Replication on RHEL 9, and How to Secure MySQL on RHEL 9.