MySQL and MariaDB are popular relational database management systems (RDBMS). While MariaDB originated as a fork of MySQL, both remain widely used and compatible. These databases offer essential features for managing data in various environments, including web applications and enterprise systems.

Installing MySQL or MariaDB on CentOS, RHEL, and Fedora is supported through their default package repositories. Both databases can be installed and managed using dnf or yum package managers. The choice between MySQL and MariaDB may depend on specific project requirements or individual preferences, as the installation procedures are nearly identical.

Both databases can be installed with simple terminal commands. Key differences in the installation process come from the names of services and binaries. Once installed, each service needs to be started and enabled for system boot. The initial setup includes configuring security options, such as password validation and user access.

Steps to install MySQL or MariaDB on CentOS, RHEL, and Fedora:

  1. 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!
  2. 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.

  3. 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; disabled; preset: >
         Active: inactive (dead)

    Check mariadb service status if you installed MariaDB server.

  4. Start the MySQL or MariaDB service.
    $ sudo systemctl start mysqld
  5. 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.
  6. 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.
  7. 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
  8. Remove the anonymous user account.
    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  9. Disable remote root login.
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  10. Remove the test database.
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  11. Reload privilege tables to apply changes.
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
  12. 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
Discuss the article:

Comment anonymously. Login not required.