Read in 3 minutes

last updated 

Install MariaDB on CentOS 7

MariaDB is an open source relational database management system, backward compatible, binary drop-in replacement of MySQL. It is developed by some of the original developers of the MySQL and by many people in the community. With the release of CentOS 7, MySQL was replaced with MariaDB as the default database system.

If for any reason you need to install MySQL, check the How to Install MySQL on CentOS 7 tutorial. If your application does not have any the specific requirements, you should stick with MariaDB,the default database system in CentOS 7.

In this tutorial we will show you how to install the latest version of MariaDB on CentOS 7 using the official MariaDB repositories. The version of the MariaDB server provided in default CentOS repositories is version 5.5 which is not the latest stable version of MariaDB.

How do I Install MariaDB on CentOS 7 ?

To install MariaDB on CentOS 7, follow these steps:

  1. Enable the MariaDB repository.

    Create a repository file named MariaDB.repo and add the following content:

    /etc/yum.repos.d/MariaDB.repo
    # MariaDB 10.3 CentOS repository list - created 2018-05-25 19:02 UTC
    # http://downloads.mariadb.org/mariadb/repositories/
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.3/centos7-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    

    At the time of writing of this article the latest version of MariaDB is version 10.3. If you need to install any other version of MariaDB, head over to the MariaDB repositories page, and generate a repository file for a specific MariaDB version.

  2. Install MariaDB with yum

    We will install the MariaDB server and client packages usingyum, same as other CentOS package by typing:

    sudo yum install MariaDB-server MariaDB-client

    Yum may prompt you to import the MariaDB GPG key:

    Retrieving key from https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    Importing GPG key 0x1BB943DB:
     Userid     : "MariaDB Package Signing Key <[email protected]>"
     Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db
     From       : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

    Type y and hit Enter.

  3. Start MariaDB service

    Once the installation is completed, enable MariaDB to start on boot and start the service:

    sudo systemctl enable mariadb
    sudo systemctl start mariadb
  4. Check MariaDB status

    Once the MySQL service is started we can check it’s status by typing:

    sudo systemctl status mariadb
    ● mariadb.service - MariaDB 10.3.7 database server
       Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
      Drop-In: /etc/systemd/system/mariadb.service.d
               └─migrated-from-my.cnf-settings.conf
       Active: inactive (dead)
         Docs: man:mysqld(8)
               https://mariadb.com/kb/en/library/systemd/

    And print the MariaDB server version, with:

    mysql -V
    mysql  Ver 15.1 Distrib 10.3.7-MariaDB, for Linux (x86_64) using readline 5.1
  5. Secure MariaDB

    Run the mysql_secure_installation command to improve the security of our MariaDB installation:

    sudo mysql_secure_installation

    The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine, and remove the test database. All steps are explained in detail and it is recommended to answer “Y” (yes) to all questions.

Connect to MariaDB from the command line

To connect to the MariaDB server through the terminal we can use the MariaDB client. Log in to the server as the root user by typing:

mysql -u root -p

You will be prompted to enter the root password you have previously set when the mysql_secure_installation script was run.

Once you enter the password you will be presented with the MariaDB shell as shown below:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.7-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Conclusion

In this tutorial, we’ve show you how to install and secure MariaDB on a CentOS 7 server. You may also want to read about how to manage MySQL user accounts and databases or how to reset a MySQL root password in case you have forgotten it.

This is a post in the Install LEMP Stack on CentOS 7 series.
Other posts in this series:

Install MariaDB on CentOS 7