Thursday, January 30, 2014

How to upgrade MySQL using RPM

Overview

This post will show you a way to upgrade your MySQL from one version to another using RPM packages.
Before using this procedure you need to have downloaded the necessary rpm packages to your server.
I used this procedure to upgrade from 5.4.xx to 5.5.27.
This was also done on a Master/Slave environment so I will give you the additional step I did.

Close your application

Before you start you should stop your application so there is no transaction.

Promote the Slave as a Master

You will have to do the following to promote the Slave to Master
  • Stop the slave process
  • Reset the slave process
  • Change the 'change master command'
  • restart mysql on the slave
stop slave;
reset slave;
change master to '';

service mysql restart

Point your application to the new Master

Now the Slave is started as a Master you could point back your application on this instance while you are upgrading the original Master.

Upgrade the Original Master

Now the Slave is started as a Master you could point back your application on this instance while you are upgrading the original Master.

In order to do an easy upgrade I will recommend to follow those steps.
  • Stop MySQL
  • Do a full backup of the /var/lib/mysql folder
  • Remove all MySQL packages using RPM
  • Validate that you have no more mysql rpm packages installed 
  • Install your new packages
  • Start MySQL
  • Validate the MySQL Version
  • Check your databases using mysqlcheck
  • Upgrade your databases
  • Stop MySQL
  • Start MySQL
  • Check your databases again using mysqlcheck 
  • Check the status

Stop Mysql

service mysql stop

Backup your mysql folder

mkdir /backup
cp -Rp /var/lib/mysql /backup/.

Remove the MySql rpm packages from your server

rpm -qa | grep -i mysql | xargs rpm -e 

Validate that all your mysql packages are removed

rpm -qa | grep -i mysql

Install the new MySQL version using RPM

Go to the folder where your packages are saved
rpm -i MySQL*.*

Note: I prefer to specify the version I want to install just in case I have multiple versions in the same folder.
So i you want to install a specific version here is an exemple
rpm -i MySQL*5.5*

Restart MySQL

service mysql start

Validate the version

mysql_config --version

Check all your databases

mysqlcheck -uroot -pyour_password --all-databases --auto-repair

If everything if good upgrade your databases

mysql_upgrade -uroot -pyour_password

Restart MySQL

service mysql restart

Validate your databases (Without auto-repair)

mysqlcheck -uroot -pyour_password --all-databases

Check the status of the upgraded instance

show master status\G

From that point if you do not have a Master/Slave environment your instance is upgraded and you just have to restart your application.

Upgrade the old Master

This part is only for those who have a Master/Slave environment.

right now only your Slave has been upgraded, so you need to upgrade your Master Environment as well.

To do so the procedure is pretty much the same as the Slave.

Here are main steps for the old master
  • Make sure the apps is still down
  • Stop the old Master instance
  • Backup the /var/lib/mysql on the old master
  • Uninstall the MySQL old RPM packages
  • Check the MySQL packages
  • Install new MySQL packages
  • Start the old Master MySQL
  • check the MySQL Version
  • Check all databases using mysqlcheck and --auto-repair
  • Upgrade all the databases 
  • Check all databases using mysqlcheck
  • Stop MySQL on the old Master
  • Start MySQL on the old Master
  • Check the instance status
From that point since both old master and Slave were synchronized, there should be no need to refresh the old Master from the upgraded Slave.

Here are the details to upgrade the old Master

Make sure the apps is still down

Check that the apps is still down

Stop the updated MySQL instance

service mysql stop

Stop the old Master instance

service mysql stop

Backup the /var/lib/mysql on the old master

mkdir /backup
cp -Rp /var/lib/mysql /backup/.

Uninstall the MySQL old RPM packages

Before uninstalling the MySQL RPM packages, make sure the new one are downloaded on the server
rpm -qa | grep -i mysql \ xargs rpm -e

Check the MySQL packages

rpm -qa | grep -i mysql

Install new MySQL packages

Go  to the folder where your packages are located
rpm -i MySQL*.*

Start the old Master MySQL

service mysql start

Check the MySQL Version

rpm -qa | grep -i mysql

Check all databases using mysqlcheck and --auto-repair

mysqlcheck -uroot -pyour_password --all-databases --auto-repair

Upgrade all the databases 

mysql_upgrade -uroot -pyour_password

Check all databases using mysqlcheck

mysqlcheck -uroot -pyour_password --all-databases

Stop MySQL on the old Master

service mysql stop

Start MySQL on the old Master

service mysql start

Check the instance status

show master status\G

Rebuild the Master/Slave environment

Since the binaries have been upgraded on both servers, the next step will be to rebuild the Master/Slave environment using a copy of the Master.

I already posted a How to create a Maste/Slave.

Here is the link : How to create a Master Slave in MySQL



No comments:

Post a Comment