How to install MySQL 5.6 on CentOS 7

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.

If you have mysql installed already you will have to shut it down to upgrade, if it is not installed then you can simply move on.
Now, if we execute on the terminal:

I you have MySQL installed run this command first:

systemctl stop mysqld

If MySQL is not installed run this command:

yum -y install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

Run this command to check if the repository is active:

yum repolist enabled | grep "mysql.*-community.*"

The next step is actually installing the server packages:

yum -y install mysql-community-server

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:

systemctl start mysqld

You can check that it started successfully by running:

systemctl status mysqld

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

systemctl enable mysqld.service

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.

Since you have installed MySQL via the 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.