Deploying MySQL or MariaDB turns a CentOS, RHEL, or Fedora host into a persistent SQL backend for web apps, automation, and local development. A packaged database server provides predictable service management, log locations, and update handling compared to ad‑hoc binaries.
On the RHEL family, installation delivers the database daemon (mysqld for MySQL or mariadb for MariaDB), client tools, and a systemd unit file. After the unit is started and enabled, the server accepts local socket connections and can listen on TCP port 3306 based on its configuration.
Service names, default authentication, and the exact mysql_secure_installation prompts vary by database flavor and distro release, and some RHEL-family releases deliver specific database versions via DNF module streams. Exposing TCP 3306 to untrusted networks is a common misstep, and remote administrative access is best handled with least‑privilege users and tight firewall rules.
Steps to install MySQL or MariaDB on CentOS, RHEL, and Fedora:
- Update the system packages.
$ sudo dnf upgrade --refresh --assumeyes Rocky Linux 9 - BaseOS 6.1 MB/s | 9.1 MB 00:01 Rocky Linux 9 - AppStream 6.4 MB/s | 12 MB 00:01 Rocky Linux 9 - Extras 24 kB/s | 17 kB 00:00 Dependencies resolved. ##### snipped ##### Complete!
On older RHEL-family systems that still use yum, replace dnf with yum.
- Install the Oracle MySQL Yum repository release package for MySQL Community Server.
$ sudo dnf install --assumeyes https://dev.mysql.com/get/mysql84-community-release-el9-2.noarch.rpm Last metadata expiration check: 0:00:32 ago on Thu Jan 1 05:57:03 2026. mysql84-community-release-el9-2.noarch.rpm 32 kB/s | 14 kB 00:00 Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mysql84-community-release noarch el9-2 @commandline 14 k ##### snipped ##### Complete!
Skip this step if you are installing MariaDB from the distro repositories.
- Install either MySQL or MariaDB package from the repository.
$ sudo dnf install --assumeyes mysql-community-server Last metadata expiration check: 0:00:41 ago on Thu Jan 1 05:57:50 2026. Dependencies resolved. ================================================================================================== Package Arch Version Repository Size ================================================================================================== Installing: mysql-community-server aarch64 8.4.7-1.el9 mysql-8.4-lts-community 49 M replacing mariadb-connector-c-config.noarch 3.2.6-1.el9_0 Installing dependencies: libaio aarch64 0.3.111-13.el9 baseos 24 k libtirpc aarch64 1.3.3-9.el9 baseos 93 k mysql-community-icu-data-files aarch64 8.4.7-1.el9 mysql-8.4-lts-community 2.3 M ##### snipped ##### Complete!Install mariadb-server instead to install MariaDB server.
- Start the MySQL or MariaDB service.
$ sudo systemctl start mysqld
Use
$ sudo systemctl start mariadb
if MariaDB was installed.
- Enable the service to start automatically on boot.
$ sudo systemctl enable mysqld
Use
$ sudo systemctl enable --now mysqld
to combine enablement and startup.
- Verify the installation by checking the service status.
$ sudo systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled) Active: active (running) since Thu 2026-01-01 05:58:51 UTC; 10s ago Status: "Server is operational" ##### snipped #####Check mariadb.service status with
$ sudo systemctl status mariadb
if MariaDB was installed.
- Run the security script to configure the database installation.
$ sudo mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: The 'validate_password' component is installed on the server. The subsequent steps will run with the existing configuration of the component. Using existing password for root.
Some MySQL packages require a temporary root password from /var/log/mysqld.log (look for temporary password) before mysql_secure_installation can connect.
- Set a password for the root user.
Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
Storing the root password in shell history or scripts can compromise the database host.
- Remove the anonymous user account.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Success.
- Disable remote root login.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y Success.
Remote administration is safer with a dedicated user restricted to required databases and hosts.
- Remove the test database.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success.
- Reload privilege tables to apply changes.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success.
- Connect to the database using the mysql client for testing.
$ mysql -u root -p -A Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 8.4.7 MySQL Community Server - GPL ##### snipped ##### mysql> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 8.4.7 | +-----------+ 1 row in set (0.00 sec) mysql> exit Bye
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
