Sometimes it is desired to use particular software versions in production, and not necessary the latest ones. There may be several reasons for that, where I think the most common is when a new version should spend some time in testing or a staging environment before getting to production. In theory each new version is supposed to be better as usually it contains a handful of bug fixes and even new or improved functionality. However there is also a risk of some regression or a new bug introduction as a side effect of code changes.
Quite often DBAs want the same MySQL version to be installed on all database instances, regardless of what actually is the latest version available in the software provider’s repository. There are several ways to achieve this:
* download specific version packages manually and then install them,
* have custom local repository mirror where you decide when and which version gets there, and just update from there using yum/apt,
* have database instance images with all software prepared,
* point to a particular version just using default package-management utility.
My idea was to remind about this last method as maybe the least known one.
In this article I will focus on YUM as it seems this is the only one currently offering multiple versions from official repositories of Oracle and Percona MySQL variants. APT theoretically is also able to install older versions, but command “apt-cache madison …” returns only the latest one for me. For example using Oracle repo:
root@ubuntu-14:~# apt-cache madison mysql-community-server mysql-community-server | 5.6.22-2ubuntu14.04 | http://repo.mysql.com/apt/ubuntu/ trusty/mysql-5.6 amd64 Packages mysql-community | 5.6.22-2ubuntu14.04 | http://repo.mysql.com/apt/ubuntu/ trusty/mysql-5.6 Sources
So let’s see how it looks like for YUM repositories. I have installed repositories from Oracle, MariaDB and Percona on Centos 6 test machine. This is what they offer for the main server package versions:
[root@localhost ~]# yum repolist repo id repo name status base CentOS-6 - Base 6,518 extras CentOS-6 - Extras 36 mariadb MariaDB 17 mysql-connectors-community MySQL Connectors Community 12 mysql-tools-community MySQL Tools Community 18 mysql56-community MySQL 5.6 Community Server 112 percona-release-noarch Percona-Release YUM repository - noarch 26 percona-release-x86_64 Percona-Release YUM repository - x86_64 432 updates CentOS-6 - Updates 530 repolist: 7,701 [root@localhost ~]# yum -q list available --showduplicates mysql-community-server.x86_64 Available Packages mysql-community-server.x86_64 5.6.15-1.el6 mysql56-community mysql-community-server.x86_64 5.6.16-1.el6 mysql56-community mysql-community-server.x86_64 5.6.17-4.el6 mysql56-community mysql-community-server.x86_64 5.6.19-2.el6 mysql56-community mysql-community-server.x86_64 5.6.20-4.el6 mysql56-community mysql-community-server.x86_64 5.6.21-2.el6 mysql56-community mysql-community-server.x86_64 5.6.22-2.el6 mysql56-community [root@localhost ~]# [root@localhost ~]# yum -q list available --showduplicates MariaDB-server.x86_64 Available Packages MariaDB-server.x86_64 10.0.15-1.el6 mariadb [root@localhost ~]# [root@localhost ~]# yum -q list available --showduplicates Percona-Server-server-56.x86_64 Available Packages Percona-Server-server-56.x86_64 5.6.13-rel61.0.461.rhel6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.14-rel62.0.483.rhel6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.15-rel63.0.519.rhel6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.16-rel64.0.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.16-rel64.1.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.16-rel64.2.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.17-rel65.0.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.17-rel66.0.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.19-rel67.0.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.20-rel68.0.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.21-rel69.0.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.21-rel70.0.el6 percona-release-x86_64 Percona-Server-server-56.x86_64 5.6.21-rel70.1.el6 percona-release-x86_64
So at least for both Oracle and Percona packages we can use yum to install several versions back (12 in case of Percona Server 5.6).
How can we do that? Let’s install Percona Server version 5.6.19. To get a full package name with it’s version, we join it’s name with version but the CPU family part needs to be removed or replaced to the end. So Percona-Server-server-56.x86_64 + 5.6.19-rel67.0.el6 -> Percona-Server-server-56-5.6.19-rel67.0.el6 or Percona-Server-server-56-5.6.19-rel67.0.el6.x86_64:
[root@localhost ~]# yum -q install Percona-Server-server-56-5.6.19-rel67.0.el6 Percona-Server-client-56-5.6.19-rel67.0.el6 Percona-Server-shared-56-5.6.19-rel67.0.el6 ============================================================================================================================= Package Arch Version Repository Size ============================================================================================================================= Installing: Percona-Server-client-56 x86_64 5.6.19-rel67.0.el6 percona-release-x86_64 6.8 M Percona-Server-server-56 x86_64 5.6.19-rel67.0.el6 percona-release-x86_64 19 M Percona-Server-shared-56 x86_64 5.6.19-rel67.0.el6 percona-release-x86_64 721 k Transaction Summary ============================================================================================================================= Install 3 Package(s) Is this ok [y/N]: y (...) [root@localhost ~]# rpm -qa|grep Percona Percona-Server-server-56-5.6.19-rel67.0.el6.x86_64 Percona-Server-client-56-5.6.19-rel67.0.el6.x86_64 Percona-Server-shared-56-5.6.19-rel67.0.el6.x86_64
But what if it happens that we have to revert to previous version? We can actually do that with YUM very quickly:
[root@localhost ~]# service mysql status SUCCESS! MySQL (Percona Server) running (1998) [root@localhost ~]# service mysql stop Shutting down MySQL (Percona Server).. SUCCESS! [root@localhost ~]# yum -q downgrade Percona-Server-server-56.x86_64 Percona-Server-client-56.x86_64 Percona-Server-shared-56.x86_64 ================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================ Downgrading: Percona-Server-client-56 x86_64 5.6.17-rel66.0.el6 percona-release-x86_64 6.8 M Percona-Server-server-56 x86_64 5.6.17-rel66.0.el6 percona-release-x86_64 19 M Percona-Server-shared-56 x86_64 5.6.17-rel66.0.el6 percona-release-x86_64 720 k Transaction Summary ================================================================================================================================ Downgrade 3 Package(s) Is this ok [y/N]: y Giving mysqld 5 seconds to exit nicely (...) [root@localhost ~]# rpm -qa|grep Percona Percona-Server-shared-56-5.6.17-rel66.0.el6.x86_64 Percona-Server-server-56-5.6.17-rel66.0.el6.x86_64 Percona-Server-client-56-5.6.17-rel66.0.el6.x86_64
What if we want to downgrade, but let’s say few versions down? It is also possible with a single YUM command. By the way, after the last step we are on Percona Server 5.6.17 rel66.0 version and YUM nicely shows that when listing all available packages, see the screen shot below:
So let’s downgrade to Percona Server 5.6.15 rel63.0 – it’s actually very easy as the “downgrade” option also understands the version attribute:
[root@localhost ~]# yum -q downgrade Percona-Server-server-56-5.6.15-rel63.0.519.rhel6 Percona-Server-client-56-5.6.15-rel63.0.519.rhel6 Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6 =================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================== Downgrading: Percona-Server-client-56 x86_64 5.6.15-rel63.0.519.rhel6 percona-release-x86_64 6.5 M Percona-Server-server-56 x86_64 5.6.15-rel63.0.519.rhel6 percona-release-x86_64 18 M Percona-Server-shared-56 x86_64 5.6.15-rel63.0.519.rhel6 percona-release-x86_64 691 k Transaction Summary =================================================================================================================================== Downgrade 3 Package(s) Is this ok [y/N]: y Giving mysqld 5 seconds to exit nicely (...)
We can do the same, or more complicated package operations, using the YUM transaction feature:
[root@localhost ~]# yum shell Loaded plugins: fastestmirror, security Setting up Yum Shell > remove Percona-Server-shared-56 Percona-Server-server-56 Percona-Server-client-56 Setting up Remove Process > install Percona-Server-server-56-5.6.15-rel63.0.519.rhel6 Percona-Server-client-56-5.6.15-rel63.0.519.rhel6 Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6 (...) Setting up Install Process > run --> Running transaction check ---> Package Percona-Server-client-56.x86_64 0:5.6.15-rel63.0.519.rhel6 will be installed ---> Package Percona-Server-client-56.x86_64 0:5.6.17-rel66.0.el6 will be erased ---> Package Percona-Server-server-56.x86_64 0:5.6.15-rel63.0.519.rhel6 will be installed ---> Package Percona-Server-server-56.x86_64 0:5.6.17-rel66.0.el6 will be erased ---> Package Percona-Server-shared-56.x86_64 0:5.6.15-rel63.0.519.rhel6 will be obsoleting ---> Package Percona-Server-shared-56.x86_64 0:5.6.17-rel66.0.el6 will be erased (...) ================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================ Installing: Percona-Server-client-56 x86_64 5.6.15-rel63.0.519.rhel6 percona-release-x86_64 6.5 M Percona-Server-server-56 x86_64 5.6.15-rel63.0.519.rhel6 percona-release-x86_64 18 M Percona-Server-shared-51 x86_64 5.1.73-rel14.12.624.rhel6 percona-release-x86_64 2.1 M replacing mysql-libs.x86_64 5.1.73-3.el6_5 Percona-Server-shared-56 x86_64 5.6.15-rel63.0.519.rhel6 percona-release-x86_64 691 k replacing mysql-libs.x86_64 5.1.73-3.el6_5 Removing: Percona-Server-client-56 x86_64 5.6.17-rel66.0.el6 @percona-release-x86_64 33 M Percona-Server-server-56 x86_64 5.6.17-rel66.0.el6 @percona-release-x86_64 86 M Percona-Server-shared-56 x86_64 5.6.17-rel66.0.el6 @percona-release-x86_64 3.4 M Transaction Summary ================================================================================================================================ Install 4 Package(s) Remove 3 Package(s) Total download size: 27 M Is this ok [y/N]: y (...) Removed: Percona-Server-client-56.x86_64 0:5.6.17-rel66.0.el6 Percona-Server-server-56.x86_64 0:5.6.17-rel66.0.el6 Percona-Server-shared-56.x86_64 0:5.6.17-rel66.0.el6 Installed: Percona-Server-client-56.x86_64 0:5.6.15-rel63.0.519.rhel6 Percona-Server-server-56.x86_64 0:5.6.15-rel63.0.519.rhel6 Percona-Server-shared-51.x86_64 0:5.1.73-rel14.12.624.rhel6 Percona-Server-shared-56.x86_64 0:5.6.15-rel63.0.519.rhel6 Replaced: mysql-libs.x86_64 0:5.1.73-3.el6_5 Finished Transaction > quit Leaving Shell [root@localhost ~]# rpm -qa|grep Percona Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6.x86_64 Percona-Server-client-56-5.6.15-rel63.0.519.rhel6.x86_64 Percona-Server-shared-51-5.1.73-rel14.12.624.rhel6.x86_64 Percona-Server-server-56-5.6.15-rel63.0.519.rhel6.x86_64
The fact that we can use single command or single YUM transaction, instead of a manual rpm download and installation, is not the only advantage of this method. The other very important one is that we don’t have to worry about breaking package dependencies when we uninstall current version manually in order to install different one, as there may be many packages that depend on MySQL.
However, if anyone does “yum update” on this system, our packages will be upgraded to the latest version, which is what we probably don’t want to happen yet, and surely not without our supervision:
[root@localhost ~]# yum -q update =================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================== Updating: Percona-Server-client-56 x86_64 5.6.21-rel70.1.el6 percona-release-x86_64 6.4 M Percona-Server-server-56 x86_64 5.6.21-rel70.1.el6 percona-release-x86_64 19 M Percona-Server-shared-56 x86_64 5.6.21-rel70.1.el6 percona-release-x86_64 721 k Transaction Summary =================================================================================================================================== Upgrade 3 Package(s) Is this ok [y/N]: N Exiting on user Command
To prevent that, we should lock our packages on current version. To achieve that, we need yum-plugin-versionlock package which allows us to do this:
[root@localhost ~]# yum versionlock Percona-Server-server-56 Percona-Server-client-56 Percona-Server-shared-56 Loaded plugins: fastestmirror, security, versionlock Adding versionlock on: 0:Percona-Server-server-56-5.6.15-rel63.0.519.rhel6 Adding versionlock on: 0:Percona-Server-client-56-5.6.15-rel63.0.519.rhel6 Adding versionlock on: 0:Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6 versionlock added: 3 [root@localhost ~]# yum update Loaded plugins: fastestmirror, security, versionlock Setting up Update Process (...) No Packages marked for Update
Now these packages cannot be updated unless you clear the locks with
yum versionlock clear
(clear any locks) or particular locks:
[root@localhost ~]# yum -q versionlock list 0:Percona-Server-server-56-5.6.15-rel63.0.519.rhel6.* 0:Percona-Server-client-56-5.6.15-rel63.0.519.rhel6.* 0:Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6.* [root@localhost ~]# yum versionlock delete '0:Percona-Server-client-56-5.6.15-rel63.0.519.rhel6.*' Loaded plugins: fastestmirror, security, versionlock Deleting versionlock for: 0:Percona-Server-client-56-5.6.15-rel63.0.519.rhel6.* versionlock deleted: 1 [root@localhost ~]# yum -q versionlock list 0:Percona-Server-server-56-5.6.15-rel63.0.519.rhel6.* 0:Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6.* [root@localhost ~]# yum -q update =================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================== Updating: Percona-Server-client-56 x86_64 5.6.21-rel70.1.el6 percona-release-x86_64 6.4 M Transaction Summary =================================================================================================================================== Upgrade 1 Package(s) Is this ok [y/N]:
I think the fact that you can install particular MySQL and Percona Server versions using YUM lets you simplify software management tools recipes, like Chef, Puppet or Ansible. For example, the Chef’s yum_package resource has version attribute, and an example recipe for Percona Server 5.6.20 installation may look like this:
pkgs = ["Percona-Server-client-56","Percona-Server-shared-56","Percona-Server-server-56","Percona-Server-56-debuginfo"] pkgs.each do |pkg| yum_package pkg do version "5.6.20-rel68.0.el6" allow_downgrade true end end
Hopefully we will see similar functionality from APT MySQL repositories eventually.
The post Using YUM to install specific MySQL/Percona Server versions appeared first on MySQL Performance Blog.