CentOS 7 and MySQL 5.6

A bit of history

The latest version of Red Hat Enterprise Linux, one of the most popular and respected Linux distributions in the server market, was released in June 2014, followed by CentOS 7 and Oracle Linux releases in July of the same year.

There are very interesting changes for database administrators in these new releases, among which I would like to highlight the fact that installer now chooses XFS as its filesystem by default, which substitutes ext4 as the preferred format for local data storage. Red Hat EL7 also includes Btrfs as a tech preview.

Regarding packages, the most impacting change is arguable the update of both MySQL and PostgreSQL versions, indeed in a need of an update, as the previous version of Red Hat, 6.5, still featured 5-year old versions of both RDBMSs, and both are currently in end of life support. The biggest surprise is that Red Hat has opted to choose MariaDB 5.5, and not Oracle, as the default MySQL-like vendor. This has the hilarious consequence that Oracle Linux actually distributes its competitor version, MariaDB on its repositories, with the aim of being 100% compatible. The difference is that, of course, Oracle offers its latest MySQL version in yum repositories, and as a consequence, it is available for install on all Red Hat-compatible versions.

Pre-requisites

In this tutorial we will show how to install MySQL 5.6 on CentOS 7, useful for those that prefer to deploy the latest MySQL GA release. 5.6 introduces a lot of improvements over MySQL 5.5, and given that Red Hat EL7 has a support cycle of at least ten years, it may become very outdated in the future. The process we are about to show for CentOS 7 will be identical on RHEL 7 and, to some extent, other yum-based distributions like the latest versions of Fedora and Amazon Linux.

Please note that the following tutorial supposes that no previous version of MySQL or MariaDB is already installed. You can use the following command: rpm -qa | grep -i mysql to check for MySQL packages that may be previously installed and you can delete them with the yum remove command.

Tutorial

The first step is to setup Oracle’s MySQL repository, for that, we can go to the mysql.com website, click on “Downloads“, then “Yum repository” and then “Red Hat Enterprise Linux 7”. At the moment of the writing of these lines, this version of the repository setup package is still in beta, but I had no problems to install it with several combinations of software and hardware. Select “Download” and you can choose to login or create an Oracle account. We can also skip that step and just copy the link on “No thanks , just start my download”. This will provide us the address of the rpm to auto-configure the MySQL Community Server repository.

Now, if we execute on the terminal:

We can check that the repository is effectively active by running:

We have done a one-time configuration that will allow us to easily install and keep to date our MySQL installation.

The next step is actually installing the server packages. For that, we write:

As you can see, the community server package defaults to the latest version of MySQL 5.6. During the installation process, only two interruptions may happen (aside from the sudo password), one for confirmation of changes, and another to import the Oracle release engineers’ key on your system, which should be fine if it matches the fingerprint a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5. Remember that for automatic processes, we can give the -y (assume yes to all) flag to yum, but I wanted to avoid that for explanation and security purposes.

We are done with the installation, now we only have to run it and test it. Remember that Red Hat Enterprise Linux 7 replaces the management of services with systemd, so the “correct” way of starting the mysql service is:

You can check that it started successfully by doing:

And now connect from localhost by doing:

Remember also to activate the mysql auto-start on boot, as you will want in most cases (this has also changed from CentOS 6):

You can check that it was enabled successfully with the previously shown ‘status’ command; it should be shown now as “enabled”.

As good administrator, the next steps will be to properly configure user accounts and securize the database service, but that is out of the scope of this tutorial.

Thanks to installing via repository, now your packages can be easily upgraded by using yum.

For a more detailed documentation, you can also review the official docs. The Oracle engineers also have an interesting story about the testing process of these packages.

I hope this tutorial has been helpful.

How to install MySQL 5.6 on CentOS 7
Tagged on:                                                                 
  • hayderabbass

    Thanks for this Awesome tuts Jaime. I have just completed your guide on a new hosting on CentOS 7.

    • Guillermo Cruz

      Not sure if this posted. Just tried your tutorial and it worked like a charm. Thanks Jaime.

  • UpForDiscussion

    Do you recall what installation type you used for CentOS (minimal, infrastructure, creative etc…) Starting off with the minimal install and can’t seem to get mysqld to fire up. Wondering if I’m missing a dependancy…

    • jynus

      I think I did a custom install, but all dependencies should be taken care by yum if you use the official CentOS or Oracle Packages. Please provide the error message/error log and if you require further help I recommend you going to http://dba.stackexchange.com

      • UpForDiscussion

        Thanks for the offer, as soon as I submitted my comment I remembered SELinux and checke my audit.log. Found that it didn’t like the mysqld process so I retried with SELinux disabled and everything works using your method above. Thanks for posting!

  • Pingback: Centos7 开发环境安装mysql社区版本 – 剑客|关注科技互联网()

  • Pingback: How to update MySQL with CentOS 6 in most unintrusive way – in regard to perl and PHP packages? [closed] | XL-UAT()

  • Pingback: Build a LAMP Stack on CentOS 7 | Rambling Biped()

  • beshoy abdelmaseh

    (sorry about bad english)

    in advance i have a centos 7
    and i want to install mysql offline using package
    MySQL-5.6.24-1.el7.x86_64.rpm-bundle which is related to redhat 7- 64
    bit from website (https://dev.mysql.com/downloads/mysql/)

    when i download it and
    install it by using command rpm

    rpm -ivh
    MySQL-client-5.6.24-1.el7.x86_64.rpm

    rpm -ivh
    MySQL-devel-5.6.24-1.el7.x86_64.rpm

    rpm -ivh
    MySQL-embedded-5.6.24-1.el7.x86_64.rpm

    rpm -ivh
    MySQL-shared-5.6.24-1.el7.x86_64.rpm

    rpm -ivh
    MySQL-server-5.6.24-1.el7.x86_64.rpm

    1)
    frist error is this

    file /usr/share/mysql/charsets/README from install of
    MySQL-server-5.6.24-1.el7.x86_64 conflicts with file from package
    mariadb-libs-1:5.5.41-2.el7_0.x86_64

    1-Solution)
    i have solved it using

    rpm -evh
    mariadb-libs-5.5.41-2.el7_0.x86_64 –nodeps
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    2)
    then i run

    rpm -ivh
    MySQL-server-5.6.24-1.el7.x86_64.rpm –> it installed successfully

    but i get a fatal error as
    the following
    [root@localhost sql]# rpm -ivh MySQL-server-5.6.24-1.el7.x86_64.rpm

    Preparing…
    ################################# [100%]

    Updating / installing…

    MySQL-server-5.6.24-1.el7 #################################
    [100%]

    warning: user mysql does not exist – using root

    warning: group mysql does not exist – using root

    FATAL ERROR: please install the following Perl modules before
    executing /usr/bin/mysql_install_db:

    Data::Dumper

    2-Solution)

    [root@localhost sql]# rpm -ivh
    perl-Data-Dumper-2.145-3.el7.x86_64.rpm

    warning: perl-Data-Dumper-2.145-3.el7.x86_64.rpm: Header V3
    RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

    Preparing…
    ################################# [100%]

    Updating / installing…

    perl-Data-Dumper-2.145-3.el7 #################################
    [100%]

    ` start mysqld at boot time
    you have to copy

    support-files/mysql.server
    to the right place for your system

    PLEASE REMEMBER TO SET A
    PASSWORD FOR THE MySQL root USER !

    To do so, start the server,
    then issue the following commands:

    /usr/bin/mysqladmin -u
    root password ‘new-password’

    /usr/bin/mysqladmin -u
    root -h localhost.localdomain password ‘new-password’

    Alternatively you can run:

    /usr/bin/mysql_secure_installation

    which will also give you the
    option of removing the test

    databases and anonymous user
    created by default. This is

    strongly recommended for
    production servers.

    See the manual for more
    instructions.

    You can start the MySQL
    daemon with:

    cd /usr ;
    /usr/bin/mysqld_safe &

    You can test the MySQL
    daemon with mysql-test-run.pl

    cd mysql-test ; perl
    mysql-test-run.pl

    Please report any problems
    at http://bugs.mysql.com/

    The latest information about
    MySQL is available on the web at

    http://www.mysql.com

    Support MySQL by buying
    support/licenses at http://shop.mysql.com

    New default config file was
    created as /usr/my.cnf and

    will be used by default by
    the server when you start it.

    You may edit this file to
    change server settings

    4 )

    -then i run

    [root@localhost sql]#
    /usr/bin/mysql_secure_installation

    NOTE: RUNNING ALL PARTS OF
    THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

    SERVERS IN PRODUCTION
    USE! PLEASE READ EACH STEP CAREFULLY!

    In order to log into MySQL
    to secure it, we’ll need the current

    password for the root user.
    If you’ve just installed MySQL, and

    you haven’t set the root
    password yet, the password will be blank,

    so you should just press
    enter here.

    Enter current password for
    root (enter for none):

    ERROR 2002 (HY000): Can’t
    connect to local MySQL server through socket
    ‘/var/lib/mysql/mysql.sock’ (2)

    Enter current password for
    root (enter for none):

    ###################################################

    my questions are :

    1) when i enter a blank
    password with command /usr/bin/mysql_secure_installation

    as above give me error as
    above . i have run mysqld_safe –skip-grant-tables &

    to solve it but i can not ->
    still i want a solution to this problem ????

    2) second question : i have
    select mysql for redhat 7 is it compatible with centos 7 or i must
    select linux version instead ?????

    3) third question : mysql
    user was created using id 992 by checking /etc/passwd

    mysql:x:992:990:MySQL
    server:/var/lib/mysql:/bin/bash

    is this will make problem
    in future as the id=992 is not root privilege and i must be below 500
    ?????

    p { margin-bottom: 0.08in; }

    4) did i select the correct
    package(MySQL-5.6.24-1.el7.x86_64.rpm-bundle.tar) or it not the
    correct package to installed on centos 7 ?????

    5) i have tried another method by install perl yum install perl and it worked successfully
    could i install perl (all packages needed) offline method ?????