Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

How to Install the Latest MySQL on Debian 9

Table Of Contents


    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Install the Latest MySQL on Debian 9](#install-the-latest-mysql-on-debian-9
    – [Add the MySQL APT Repository](#add-the-mysql-apt-repository
    – [Install MySQL](#install-mysql
    – [Secure MySQL](#secure-mysql
    – [Test MySQL](#test-mysql
    – [Conclusion](#conclusion

    ## Introduction

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

    [MySQL](https://www.mysql.com/ is one of the most popular open-source database management systems in the world. It uses a relational database and a [Structured Query Language (SQL](https://en.wikipedia.org/wiki/SQL to manage data. Debian 9 prefers [MariaDB](https://mariadb.org/, 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 MariaDB installation for reference, follow our guide, [How to Install MariaDB on Debian 9](https://systemongrid.com/support/guides/-how-to-install-mariadb-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 MySQL on Debian 9, you should have access to the Debian 9 server, created a non-root user account with sudo privileges and set up a firewall by following our guide, [Initial server setup with Debian 9](https://systemongrid.com/support/guides/initial-server-setup-with-debian-9.

    ## Install the Latest MySQL on Debian 9

    ## Add the MySQL APT Repository

    As we mentioned earlier, Debian 9 prefers MariaDB. So, you need to visit the MySQL APT Repository which provides MySQL packages.

    Locate the desired MySQL version and update it using the below command.

    ![debianmysqlaptrepository](https://grid.media/assets/images/add-mysql-apt-repository-02132019.png

    “`
    $ cd /tmp
    $ wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
    “`

    After saving the rpm file, verify the authenticity of the download using the below the command.

    “`
    $ md5sum mysql-apt-config_0.8.12-1_all.deb
    “`

    Verify your output with the relevant MD5 value on MySQL APT Repository website.

    ![debianmysqlapt](https://grid.media/assets/images/mysql-apt-repository-02132019.png

    If it is matched, you are all set to install.

    “`
    $ sudo dpkg -i mysql-apt-config*
    “`

    Then, you will get the following screen. Select your preferred version of MySQL. Then, go to “ok” menu option and hit the ENTER button.

    ![debianmysqlaptconfiguration](https://grid.media/assets/images/configuring-mysql-apt-config-02132019.png

    Then, refresh the cache of your apt package to make the new packages available.

    “`
    $ sudo apt update
    “`

    ## Install MySQL

    Use the apt command to install the latest MySQL server package.

    “`
    $ sudo apt install mysql-server
    “`

    Then, you will be asked if you want to continue the installation, then enter “Y”, hit the ENTER button.

    Then, you will get the following screen and asked to enter the root password. enter a strong password, confirm it by re-entering and hit on “ok”.

    ![debianmysqlpackageconfiguration](https://grid.media/assets/images/mysql-package-configuration-02132019.png

    Then, you will see the below screen. Read it and hit on “ok”.

    ![debianmysqlcommunityserver](https://grid.media/assets/images/configuring-mysql-community-server-02132019.png

    Then, you are asked to select a default authentication plugin. Select the option, Use Strong Password Encryption and hit on “ok”.

    ![debianmysqldefaultauthenticationplugin](https://grid.media/assets/images/default-authentication-plugin-02132019.png

    With this, you have successfully installed the MySQL and it is running now. Check the status of the MySQL using the below command.

    “`
    $ sudo systemctl status mysql
    “`

    Output:

    ![debianmysqlstatus](https://grid.media/assets/images/mysql-status-02132019.png

    The above output shows that your MySQL is installed and running successfully.

    ## Secure MySQL

    MySQL 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
    “`

    The script will ask you to give a password for further use within the MySQL system. Then, you will be asked, if you want to configure the VALIDATE PASSWORD PLUGIN. Press Y for yes, or any other key to continue without enabling.

    ![debianmysqlsecure](https://grid.media/assets/images/securing-mysql-02132019.png

    Then, you will be asked to select a level of password validation.

    ![debianmysqlpasswordvalidation](https://grid.media/assets/images/password-validation-policy-02132019.png

    Select any one among three levels of password validation, enter your new password. Then, you will be shown the strength of the password you have entered. Press Y if you are satisfied with the password.

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

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

    ![debianmysqldisallowrootlogin](https://grid.media/assets/images/disallow-root-login-remotely-02132019.png

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

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

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

    ![debianmysqlreloadprivileges](https://grid.media/assets/images/reload-privileges-tables-02132019.png

    ## Test MySQL

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

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

    Output:

    ![debianmysqlversion](https://grid.media/assets/images/mysql-version-02132019.png

    The above output shows that you have successfully installed the latest MySQL on Debian 9.

    ## Conclusion

    In this guide, you have learned how to install the latest MySQL on Debian 9 and some additional recommended steps that must be taken to increase the usability and security of your server.