How to Install MySQL 5.6 on CentOS 6.x

Today I had to upgrade my MySQL server from MySQL 5.5 to MySQL 5.6. This was the procedure I used to update, but you can also use it to install from scratch if you need. Let’s begin with this guide to show you how to install MySQL 5.6 on CentOS 6.

Requirements

  • Plain CentOS 6 box (without cPanel)
  • Fresh backups of all your MYSQL Databases: while this rpm installation / upgrade shouldn’t affect your databases, it is recommended to have a fresh backup of all your databases.

To backup all your mysql databases you can use this quick line:

mysqldump -u root -p --all-databases > /tmp/all-databases.sql

This will prompt for your root password and generate an all in one MySQL dump located at  /tmp/all-databases.sql

Step 1: Install the MySQL Community repository

It doesn’t matter if you already have MySQL installed or not, this will replace your current MySQL rpms if a previous MYSQL version exists, like it did in my case. This is really important, you must always create your own full backups of all your databases before proceeding with our tutorial on how to install mysql 5.6 on CentOS 6.x.

The first thing you need to do is to setup the official MySQL Community repository, from where we are going to take the MySQL 5.6 rpms. This can be done using this commands:

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -Uvh mysql-community-release-el6-5.noarch.rpm

At this point you should be ready to install MySQL 5.6 on CentOS 6.

Step 2: Install MySQL 5.6 on CentOS 6

Type in the following commands to install MySQL 5.6

yum mysql mysql-server -y

The output should be similar to this:

[[email protected]:~]yum install mysql mysql-server -y
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
...
...
...
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.6.35-2.el6.x86_64 1/7
Installing : mysql-community-libs-5.6.35-2.el6.x86_64 2/7
Installing : mysql-community-client-5.6.35-2.el6.x86_64 3/7
Installing : mysql-community-server-5.6.35-2.el6.x86_64 4/7
warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
Erasing : mysql-server-5.5.54-1.el6.remi.x86_64 5/7
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
Erasing : mysql-5.5.54-1.el6.remi.x86_64 6/7
Erasing : mysql-libs-5.5.54-1.el6.remi.x86_64 7/7
Verifying : mysql-community-common-5.6.35-2.el6.x86_64 1/7
Verifying : mysql-community-libs-5.6.35-2.el6.x86_64 2/7
Verifying : mysql-community-server-5.6.35-2.el6.x86_64 3/7
Verifying : mysql-community-client-5.6.35-2.el6.x86_64 4/7
Verifying : mysql-5.5.54-1.el6.remi.x86_64 5/7
Verifying : mysql-libs-5.5.54-1.el6.remi.x86_64 6/7
Verifying : mysql-server-5.5.54-1.el6.remi.x86_64 7/7

Installed:
mysql-community-client.x86_64 0:5.6.35-2.el6
mysql-community-libs.x86_64 0:5.6.35-2.el6 mysql-community-server.x86_64 0:5.6.35-2.el6

Dependency Installed:
mysql-community-common.x86_64 0:5.6.35-2.el6

Replaced:
mysql.x86_64 0:5.5.54-1.el6.remi mysql-libs.x86_64 0:5.5.54-1.el6.remi
mysql-server.x86_64 0:5.5.54-1.el6.remi

Complete!
[[email protected]:~]

A real picture from the MySQL 5.6 installation process:

install mysql 5.6 on CentOS 6.x
Screenshot of installing mysql 5.6 on CentOS 6.x using yum package manager.

Type the following command to check if all the MySQL 5.6 rpm packages were installed ok:

rpm -qa | grep mysql

The output should look like this:

[[email protected]:~]rpm -qa | grep mysql
mysql-community-client-5.6.35-2.el6.x86_64
mysql-community-server-5.6.35-2.el6.x86_64
php-mysqlnd-5.6.30-1.el6.remi.x86_64
mysql-community-common-5.6.35-2.el6.x86_64
mysql-community-libs-5.6.35-2.el6.x86_64
mysql-community-release-el6-5.noarch
[[email protected]:~]

Start MySQL 5.6 and add the service to the boot process:

chkconfig mysqld on
service mysqld start

Verify that MySQL 5.6 is running

[[email protected]:~]mysql -V
mysql Ver 14.14 Distrib 5.6.35, for Linux (x86_64) using EditLine wrapper

Now try to connect to your MySQL console:

[[email protected]:~]mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 280
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Now restart MySQL to make sure everything is working as expected in your websites.

service mysqld restart

If MySQL fails to start like this:

[[email protected]:~]service mysqld restart
Stopping mysqld:                                           [  OK  ]
MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]

Check out your MySQL logs, it is possible that old deprecated my.cnf variables are no longer working on 5.6 version, like it happened to me:

[[email protected]:~]tail -100 /var/log/mysqld.log | grep ERR -i
2017-02-06 12:06:34 28942 [ERROR] /usr/sbin/mysqld: unknown variable 'table_cache=26536'
2017-02-06 12:06:34 28942 [ERROR] Aborting

In my case and old deprecated ‘table_cache’ was preventing MySQL 5.6 from starting ok, removed that from /etc/my.cnf file, restarted again and it was all working:

[[email protected]:~]service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[[email protected]:~]

That’s all. As you see, upgrading to MySQL 5.6 from 5.5 or installing MySQL 5.6 on CentOS from the official MySQL Community Repo is pretty easy.
And, in the case something goes really wrong, you can delete your 5.6 version and reinstall 5.5 to recover all your databases from the backup made before.

Please let me know if you have any questions or concerns about this tutorial. Were you able to install MySQL 5.6 on CentOS 6 at the end?

Useful links:

About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

2 Comments

  1. Is there any particular benefit in using MySQL community repo instead of using MySQL provided by cPanel?

    cPanel within WHM interface also allows upgrading and switching between MySQL versions. Downgrade is not recommended though…

    1. Hello Ivan,

      There isn’t in fact. This article, as stated at the beginning of the post, requires a “Plain CentOS 6 box (without cPanel)”. If it was cPanel there would be no need to use external repos as cPanel handles MySQL upgrades and version switch very well.

      Thanks for your comment anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *