Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

How to Install MySQL on CentOS 7

Table Of Contents


    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Install MySQL on CentOS 7](#install-mysql-on-centos-7
    – [Install MySQL](#install-mysql
    – [Start MySQL](#start-mysql
    – [Configure MySQL](#configure-mysql
    – [Test MySQL](#test-mysql
    – [Conclusion](#conclusion

    ## Introduction

    In this guide, we are going to explain to you how to install MySQL on CentOS 7 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 is commonly installed as a part of the LEMP stack. To manage data, MySQL uses a relational database and a [Structured Query Language (SQL](https://en.wikipedia.org/wiki/SQL.

    CentOS 7 prefers [MariaDB](https://mariadb.org/, which is developed by the MySQL developers as a replacement for MySQL. MariaDB will be installed even if you run the yum install mysql command on CentOS 7. So, if you want MariaDB installation for reference, follow our guide, [How to Install MariaDB on CentOS 7](https://systemongrid.com/support/guides/how-to-install-mariadb-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 MySQL, 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 MySQL on CentOS 7

    ## Install MySQL

    As we mentioned earlier, MariaDB will be installed even if you run the yum install mysql command on CentOS 7. So, you need to visit the MySQL Yum Repository which provides MySQL packages.

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

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

    “`
    $ wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
    “`

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

    “`
    $ md5sum mysql80-community-release-el7-2.noarch.rpm
    “`

    Output:

    ![](http://

    Verify the above output with the relevant MD5 value on MySQL Yum Repository website.

    ![centosmysqlverifymd5value](https://grid.media/assets/images/verify-md5-value-02132019.png

    Once you have verified the file is authentic, install the package.

    “`
    $ sudo rpm -ivh mysql80-community-release-el7-2.noarch.rpm
    “`

    The above command adds two MySQL yum repositories, and you can use them to install the MySQL server.

    “`
    $ sudo yum install mysql-server
    “`

    Enter “Y” to confirm that you want to continue.

    ![centosmysqlconfirminstallation](https://grid.media/assets/images/confirm-installing-mysql-on-centos7-02132019.png

    You will also be asked to accept its GPG key. Enter “Y” to confirm that you want to continue.

    ![centosmysqlacceptgpakey](https://grid.media/assets/images/accept-gpg-key-02132019.png

    ## Start MySQL

    Start the MySQL daemon using the command:

    “`
    $ sudo systemctl start mysqld
    “`

    Check the status of the MySQL server.

    “`
    $ sudo systemctl status mysqld
    “`

    Output:

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

    A temporary password must have generated for the root user. You can locate the password in the mysqld.log.

    “`
    $ sudo grep ‘temporary password’ /var/log/mysqld.log
    “`

    Output:

    ![centosmysqltemporarypassword](https://grid.media/assets/images/root-temporary-password-02132019.png

    ## Configure 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
    “`

    You will be asked to enter the default root password (the temporary password. 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.

    ![centosmysqlsecureserver](https://grid.media/assets/images/secure-mysql-server-deployment-02132019.png

    You will get the estimated strength of the password and asked if you wish to continue with the password provided. Enter “Yes” to continue or “No” to enter another strong password.

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

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

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

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

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

    ![centosmysqlreloadprivileges](https://grid.media/assets/images/centos7-mysql-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 a root user using the below command.

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

    Output:

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

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

    ## Conclusion

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