Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

How to Install MariaDB on Debian 9

Table Of Contents


    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Install MariaDB on Debian 9](#install-mariadb-on-debian-9
    – [Install MariaDB](#install-mariadb
    – [Configure MariaDB](#configure-mariadb
    – [Adjust User Authentication and Privileges – Optional](#adjust-user-authentication-and-privileges-optional
    – [Test MariaDB](#test-mariadb
    – [Conclusion](#conclusion

    ## Introduction

    In this guide, we are going to explain to you how to install MariaDB on Debian 9 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 an open-source database management system, developed by the MySQL developers as a replacement for MySQL. Debian 9 prefers MariaDB, which is developed by the MySQL developers as a replacement for MySQL. MariaDB is the default MySQL variant on Debian 9. So, if you want MySQL installation for reference, follow our guide, [How to Install the Latest MySQL on Debian 9](https://systemongrid.com/support/guides/how-to-install-the-latest-mysql-on-debian-9. 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 on Debian 9, you should have access to the Debian server and created a non-root user account with sudo privileges by following our guide, [Initial server setup with Debian 9](https://systemongrid.com/support/guides/initial-server-setup-with-debian-9.

    ## Install MariaDB on Debian 9

    ## Install MariaDB

    Before installing MariaDB, you need to update the packages on your server.

    “`
    $ sudo apt update
    “`

    Then, install the MariaDB package.

    “`
    $ sudo apt install mariadb-server
    “`

    ## Configure MariaDB

    Now, it is time for you to secure the MariaDB server. It 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 and if you want to change the root password. Since you already have a root password, you can answer “n”.

    ![debianmariadbskiprootpassword](https://grid.media/assets/images/skip-root-password-change-02132019.png

    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.

    ![debianmariadbremoveusers](https://grid.media/assets/images/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.

    ![debianmariadbrootlogin](https://grid.media/assets/images/mariadb-root-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.

    ![debianmariadb](https://grid.media/assets/images/remove-test-database-and-reload-privilege-tables-02132019.png

    Finally, you will get the following output.

    ![debianmariadbissecure](https://grid.media/assets/images/mariadb-installation-is-secure-02132019.png

    ## Adjust User Authentication and Privileges – Optional

    Instead of modifying the root account, it is highly recommended to create a new user with root privileges for administrative tasks and password-based access.

    To do so, open the MariaDB prompt.

    “`
    $ sudo mysql
    “`

    Use the below command to create a new user. Replace the user name and password to match your details.

    “`
    MariaDB [(none]> GRANT ALL ON *.* TO ‘systemongrid’@’localhost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;
    “`

    Now, run the below command to make your changes effective.

    “`
    MariaDB [(none]> FLUSH PRIVILEGES;
    “`

    Then, exit the MariaDB Prompt.

    “`
    MariaDB [(none]> exit
    “`

    ## Test MariaDB

    You have installed and secured the MariaDB. Now, its time for you to test the MariaDB.

    For that, check the status of the MariaDB database server.

    “`
    $ sudo systemctl status mariadb
    “`

    Output:

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

    The above output shows that the MariaDB database server is active and running.

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

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

    Output:

    ![debianmariadbtesting](https://grid.media/assets/images/testing-the-mariaDB-installation-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 Debian 9 and some additional steps that must be taken to increase the usability and security of your server.