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 update [sudo] password for user: CentOS Stream 9 - BaseOS 2.1 MB/s | 4.7 MB 00:02 CentOS Stream 9 - AppStream 2.2 MB/s | 14 MB 00:06 CentOS Stream 9 - Extras packages 3.0 kB/s | 10 kB 00:03 Dependencies resolved. Nothing to do. Complete!
On older RHEL-family systems that still use yum, replace dnf with yum.
- Install either MySQL or MariaDB package from the repository.
$ sudo dnf install mysql-server Last metadata expiration check: 0:03:24 ago on Sun 12 Feb 2023 06:37:41 AM +08. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mysql-server aarch64 8.0.30-3.el9 appstream 16 M Installing dependencies: mariadb-connector-c-config noarch 3.2.6-1.el9 appstream 11 k mecab aarch64 0.996-3.el9.3 appstream 344 k mysql aarch64 8.0.30-3.el9 appstream 2.9 M mysql-common aarch64 8.0.30-3.el9 appstream 75 k mysql-errmsg aarch64 8.0.30-3.el9 appstream 484 k mysql-selinux noarch 1.0.5-1.el9 appstream 36 k protobuf-lite aarch64 3.14.0-13.el9 appstream 217 k Transaction Summary ================================================================================ Install 8 Packages Total download size: 20 M Installed size: 175 M
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 Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
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 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled) Active: active (running) since Sun 12 Feb 2023 06:44:12 AM +08; 8s ago ##### 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. Connecting to MySQL using a blank password.
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.
Please set the password for root here. 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
- Disable remote root login.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
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
- Reload privilege tables to apply changes.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
- Connect to the database using the mysql client for testing.
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.30 Source distribution mysql> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 8.0.30 | +-----------+ 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.
Comment anonymously. Login not required.
