How to upgrade mysql on CentOS6?

On CentOS6, the version of  mysql is typically V5.1.

mysql -V

mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

rpm -q mysql
mysql-5.1.73-7.el6.x86_64

rpm -qa|grep mysql

mysql-libs-5.1.73-7.el6.x86_64
php-mysql-5.3.3-47.el6.x86_64
mysql-5.1.73-7.el6.x86_64
mysql-server-5.1.73-7.el6.x86_64

Sometimes you may want to upgrade mysql from 5.1 to 5.5 or higher so that you can use the advanced features of mysql such as the Barracuda file format for innodb. mysql 5.1 does not support Barracuda file format and will failed to start with the error:

/usr/libexec/mysqld: unknown variable ‘innodb_file_format=Barracuda’

Simple use “yum upgrade mysql” can not upgrade mysql to 5.5 or higher because the official yum repository for CentOS 6 only includes earlier version of mysql. You should use remi repository to get the higher version of mysql.

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm && rpm -Uvh epel-release-latest-6.noarch.rpm

wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm

(or wget https://rpms.remirepo.net/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm)

vi /etc/yum.repos.d/remi.repo

[remi]
name=Remi’s RPM repository for Enterprise Linux 6 – $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

 

Then

yum -y update mysql*

to install mysql 5.5

rpm -qa | grep mysql
mysql-5.5.56-1.el6.remi.x86_64
mysql-server-5.5.56-1.el6.remi.x86_64
php-mysql-5.4.45-13.el6.remi.x86_64
mysql-libs-5.5.56-1.el6.remi.x86_64
compat-mysql51-5.1.73-1.el6.remi.x86_64

Note that this not only upgrades mysql to V5.5 but also upgrades php-mysql to higher version.

Posted in tips of hosting