Installing MySQL on Linux Using Yum Repos

This installation is done on a CentOS 7 box, but the same steps can be used for Linux servers which provides RPM packages for installing the MySQL server.

Follow the steps below to install MySQL 5.6 with the MySQL Yum repository:

1. Adding the MySQL Yum Repository

Add the MySQL Yum repository to your system's repository list. Follow these steps:

  • Go to the Download MySQL Yum Repository page in the MySQL Developer Zone.
  • Select and download the release package for your platform.



  • Install the downloaded release package with the following command
  • # yum localinstall mysql80-community-release-el7-3.noarch.rpm
    The installation command adds the MySQL Yum repository to your system's repository list and downloads the GnuPG key to check the integrity of the software packages.
    You can check that the MySQL Yum repository has been successfully added by the following command
    # yum repolist enabled | grep "mysql.*-community.*"

    2. Selecting a Release Series

    Within the MySQL Yum repository, different release series of the MySQL Community Server are hosted in different subrepositories. The subrepository for the latest GA series (currently MySQL 8.0) is enabled by default, and the subrepositories for all other series (for example, the MySQL 5.7 series) are disabled by default. Use this command to see all the subrepositories in the MySQL Yum repository, and see which of them are enabled or disabled 
    # yum repolist all | grep mysql
    To install the latest release from the latest GA series, no configuration is needed. To install the latest release from a specific series other than the latest GA series, disable the subrepository for the latest GA series and enable the subrepository for the specific series before running the installation command. 
    I will be disabling the default 8.0 series to install the 5.6 series. 
    If your platform supports yum-config-manager, you can do that by issuing these commands, which disable the subrepository for the 8.0 series and enable the one for the 5.6 series:

    # yum-config-manager --disable mysql80-community
    # yum-config-manager --enable mysql56-community

    Beside yum-config-manager command, you can select a release series by editing manually the /etc/yum.repos.d/mysql-community.repo file. This is a typical entry for a release series' subrepository in the file:

    [mysql80-community]
    name=MySQL 8.0 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    Find the entry for the subrepository you want to configure, and edit the enabled option. Specify enabled=0 to disable a subrepository, or enabled=1 to enable a subrepository.

    Since we will be installing MySQL 5.6, make sure you have enabled=0 for the above subrepository entry for MySQL 8.0, and have enabled=1 for the entry for the 5.6 series:

    # Enable to use MySQL 5.6
    [mysql56-community]
    name=MySQL 5.6 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    You should only enable subrepository for one release series at any time. When subrepositories for more than one release series are enabled, the latest series will be used by Yum.
    Verify that the correct subrepositories have been enabled by running the following command and checking its output
    # yum repolist enabled | grep mysql

    3. Installing MySQL

    Install MySQL by the following command.
    # yum install mysql-community-server

    This installs the package for MySQL server (mysql-community-server) and also packages for the components required to run the server, including packages for the client (mysql-community-client), the common error messages and character sets for client and server (mysql-community-common), and the shared client libraries (mysql-community-libs).

    4. Starting the MySQL Server

    Start the MySQL server with the following command:
    # service mysqld start
    You can check the status of the MySQL server with the following command:
    # service mysqld status

    At the initial start up of the server, the following happens, given that the data directory of the server is empty:
    • The server is initialized.
    • SSL certificate and key files are generated in the data directory.
    • validate_password is installed and enabled.
    • A superuser account 'root'@'localhost is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:
    # grep 'temporary password' /var/log/mysqld.log
    If no temporary password is displayed from the log it means no password was set for root user, you can login to mysql server as root without providing any password. But if a temporary password is displayed, change the root password as soon as possible by logging in with the generated, temporary password and set a custom password for the superuser account.

    Note!!
    validate_password is installed by default. The default password policy implemented by validate_password requires that passwords contain at least one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.

    Caution: Any information or materials on this blog is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.












    Comments