Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

How to Install MariaDB on CentOS 7

Table Of Contents


    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Install MariaDB on CentOS 7](#install-mariadb-on-centos-7
    – [Install MariaDB](#install-mariadb
    – [Secure MariaDB Server](#secure-mariadb-server
    – [Test the Installation](#test-the-installation
    – [Conclusion](#conclusion

    ## Introduction

    In this guide, we are going to explain to you how to install MariaDB on CentOS 7 and some additional recommended steps that you must take to increase the usability and security of your server.

    [MariaDB](https://mariadb.org/ is one of the most popular database servers in the world. It is commonly installed as a part of the LEMP stack. It is an open-source database management system, developed by the MySQL developers as a replacement for MySQL. So, if you want MySQL installation for reference, follow our guide, [How to Install MySQL on CentOS 7](https://systemongrid.com/support/guides/how-to-install-mysql-on-centos-7. Between MySQL and MariaDB, [MariaDB is the preferable package and can work better](https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/.

    ## Prerequisites

    Before installing MariaDB, you should have access to the CentOS 7 server and created a non-root user account with sudo privileges by following our guide, [Initial server setup with CentOS 7](https://systemongrid.com/support/guides/initial-server-setup-with-centos-7.

    ## Install MariaDB on CentOS 7

    ## Install MariaDB

    Install MariaDB packages using the below command. Press “Y” when you are asked to confirm the installation.

    “`
    $ sudo yum install mariadb-server
    “`

    After the installation is done, start the MariaDB server using the below command.

    “`
    $ sudo systemctl start mariadb
    “`

    Now, check the status of the MariaDB server to make sure you have done the installation successfully.

    “`
    $ sudo systemctl status mariadb
    “`

    Output:

    ![centosmariadbstatus](https://grid.media/assets/images/centos7-mariadb-status-02132019.png

    In the above output, you can clearly see that the MariaDB service is active and running.

    Now, check if the MariaDB is starting at boot. You can do it by using the below command.

    “`
    $ sudo systemctl enable mariadb
    “`

    Output:

    ![centosmariadbenabled](https://grid.media/assets/images/centos7-mariadb-enabled-02132019.png

    ## Secure MariaDB Server

    Now, it is time for you to secure the MariaDB server.

    MariaDB uses a security script to modify the default security options like remote logins. Use the below command to run the security script.

    “`
    $ sudo mysql_secure_installation
    “`

    Then, you will be asked to enter the root password, which hasn’t set yet so you can hit the ENTER button.

    ![centosmariadbrootpassword](https://grid.media/assets/images/centos7-mariadb-root-password-02132019.png

    After this, you will be asked to set a password for the root account. Enter “Y” if you want to set a password. After entering “Y”, you will need to enter a password and confirm it by re-entering the password.

    ![centosmariadbsetrootpassword](https://grid.media/assets/images/centos7-mariadb-set-root-password-02132019.png

    If you don’t want to set a password for the root, you can also skip the above step by pressing the ENTER button. But, it is highly recommended to set a strong password for the root.

    Then, you will be asked if you want to remove anonymous users. Press Y for yes, or any other key to continue. (We recommend accepting all the below security suggestions by entering “Y” in each step.

    ![centosmariadbremoveusers](https://grid.media/assets/images/centos7-mariadb-remove-anonymous-users-02132019.png

    Then, you will be asked if you want to disallow root login remotely. Press Y for yes, or any other key to continue.

    ![centosmariadbdisallowrootlogin](https://grid.media/assets/images/centos7-mariadb-disallow-remote-login-02132019.png

    Then, you will be asked to remove the test database and reload privilege tables. Press Y for yes, or any other key to continue.

    ![centosmariadbremovetestdatabase](https://grid.media/assets/images/centos7-mariadb-remove-test-database-02132019.png

    Finally, you will get the following output.

    ![centosmariadbinstallationcompleted](https://grid.media/assets/images/mariadb-installation-completed-02132019.png

    ## Test the Installation

    You can test your installation and know the information about it. For that, you need to connect to your MariaDB server as a root user (or, a user with password authentication using the below command.

    “`
    $ mysqladmin -u root -p version
    “`

    Output:

    ![centosmariadbversion](https://grid.media/assets/images/centos7-mariadb-version-02132019.png

    The above output shows that the MariaDB installation has been successful.

    ## Conclusion

    In this guide, you have learned how to install MariaDB on CentOS 7 and some additional steps that must be taken to increase the usability and security of your server.