How to Upgrade MySQL on Debian and Ubuntu

        One of the daily tasks of a system administrator is upgrading services, applying patches, or rolling out fancy new features. In early 2013, the latest MySQL 5.6 was released, aiming to deliver better performance and scalability. If you’re interested, you might want to check out this guide I wrote on How to Upgrade MySQL on Debian and Ubuntu.

In this tutorial, I will assume you have already installed MySQL via apt-get. At the time of writing, most Linux distributions ship with MySQL 5.5. Here, I will show you how to upgrade from MySQL 5.5 to 5.6.

Step 1: Back up MySQL configuration files.

$ sudo mkdir /backup$ sudo tar cvfvz /backup/mysql_conf.tgz /etc/mysql

Step 2: Export the database to a .sql file, and also back up the data directory.

$ sudo sh -c 'mysqldump -u root -p -A --events > /backup/backup_db.sql$ sudo tar cvfvz /backup/mysql_data.tgz /var/lib/mysql

Note: If you have continuous backups set up for your live MySQL system, it is strongly recommended that you use the single-transaction option or explicitly use locks when performing the steps above (to ensure data consistency —— translator’s note). See this tutorial for details.

Step 3: Stop the MySQL service

$ sudo service mysql stop

Step 4: Uninstall MySQL packages

$ sudo apt-get remove mysql-server mysql-client mysql-common$ sudo apt-get autoremove$ sudo apt-get autoclean

Do not use the purge option with apt-get remove, as this would delete MySQL configuration files and other data needed later.

Step 5: Install MySQL dependency packages (Kernel Asynchronous I/O access library), which MySQL 5.5 and later versions depend on.

$ sudo apt-get install libaio1

Step 6: Download the Debian MySQL package from the official website

32-bit system:

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15-debian6.0-i686.deb

64-bit system:

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15-debian6.0-x86_64.deb

Step 7: Install the MySQL package

$ sudo dpkg -i mysql-5.6.15-debian6.0-*.deb

This package will be installed under the /opt/mysql directory.

Step 8: Add the MySQL binary path to the system PATH environment variable.

On Debian:

$ sudo sh -c 'echo "PATH=$PATH:/opt/mysql/server-5.6/bin" >> /etc/profile'$ source /etc/profile

On Ubuntu or Linux Mint:

$ sudo sh -c 'echo "PATH=${PATH}:/opt/mysql/server-5.6/bin" >> /etc/environment'$ source /etc/environment

Step 9: Enter the MySQL configuration file and modify the following two lines.

$ sudo vi /etc/mysql/my.cnf

basedir = /opt/mysql/server-5.6

lc-messages-dir = /opt/mysql/server-5.6/share

Step 10: Set up the init script

Copy the MySQL startup script to the /etc/init.d directory and configure it to run at boot, so MySQL will start automatically when the system boots up.

$ sudo cp /opt/mysql/server-5.6/support-files/mysql.server /etc/init.d/mysql$ sudo update-rc.d mysql defaults

Step 11: (Ubuntu Only) Edit the AppArmor configuration

The previous MySQL version created a profile for the AppArmor service upon installation. This profile remains in the system after MySQL is uninstalled, but it is incompatible with the currently installed MySQL version. You need to re-edit this profile before the MySQL service can start properly.

First, create a symbolic link.

$ sudo ln -s /opt/mysql/server-5.6/bin/mysqld /usr/sbin/mysqld

Then edit the MySQL AppArmor profile.

$ sudo vi /etc/apparmor.d/usr.sbin.mysqld

/opt/mysql/server-5.6/lib/plugin/ r,

/opt/mysql/server-5.6/lib/plugin/.so mr,

/opt/mysql/server-5.6/share/** r,

Finally, restart the AppArmor service.

$ sudo service apparmor restart

Step 12: (Again, Ubuntu Only) Remove the upstart config file left by the previous MySQL version.

This version of MySQL uses SysVinit (i.e., /etc/init.d/mysql) instead.

$ sudo rm /etc/init/mysql.conf

Step 13: Start the MySQL service.

$ sudo service mysql start

Step 14: Restore the MySQL databases.

$ sudo mysql -u root -p < /backup/backup_db.sql

Step 15: Finally, upgrade the MySQL system tables.

$ sudo /opt/mysql/server-5.6/bin/mysql_upgrade -v -u root -p

Troubleshooting MySQL Upgrade Issues

If the MySQL service fails to start on Ubuntu with the following error, it is because the old MySQL AppArmor profile is preventing it from running. You need to update the AppArmor profile as described in Step 11.

Dec 20 19:57:48 ubuntu kernel: [ 5856.960592] type=1400 audit(1387598268.807:39): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=25216 comm="apparmor_parser"

via: http://xmodulo.com/2013/12/upgrade-mysql-server-debian-ubuntu.html

Translator: bazz2 Proofreader: Caroline

This article was originally translated by LCTT and proudly presented by Linux China.

Article URL: http://linux.cn/thread/12214/1/1/

Leave a Comment

Your email address will not be published.