One of the daily tasks of a system administrator is upgrading services, applying patches, or adding some fancy new features. In early 2013, the latest MySQL 5.6 was released, aiming to provide better performance and scalability. If you’re interested, you might want to check out this article I wrote on how to upgrade MySQL on Debian and Ubuntu.
In this tutorial, I’ll assume you’ve already installed MySQL via apt-get. At the time of writing, most Linux distributions deploy MySQL 5.5. Here, I’ll 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 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 maintain continuous backups for your production 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). 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 will delete MySQL configuration files and other data you will need later.
Step 5: Install the MySQL dependency package (Kernel Asynchronous I/O access library), required by MySQL 5.5 and later.
$ 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 command 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: Edit 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 startup script
Copy the MySQL startup script to the /etc/init.d directory and configure it to run at boot so that MySQL starts 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 version of MySQL created a configuration file for the AppArmor service during installation. This file remains on the system after MySQL is uninstalled, but it is incompatible with the currently installed MySQL version. You need to re-edit this configuration file 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 configuration file.
$ 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 auto-start configuration file left over from 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 database.
$ 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 you encounter the following error when starting the MySQL service on Ubuntu, it’s because the old MySQL AppArmor configuration file is preventing it from running. You need to update the AppArmor configuration file by following 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 is an original translation by LCTT, proudly presented by Linux China.
Article URL: http://linux.cn/thread/12214/1/1/