Skip to main content

Upgrade MySQL 5.1 to MySQL 5.7 on CentOS


Upgrading MySQL is pretty straight forward, however there are some catches. Per MySQL’s official documentation, you must upgrade from 5.1 to 5.5, then upgrade from 5.5 to 5.6, and finally again from 5.6 to 5.7. You cannot upgrade from 5.1 directly to 5.7.
This guide will outline how to upgrade MySQL 5.1 to MySQL 5.7 in sequence and will assume you are using the IUS repositories for MySQL. If the IUS repositories are not already setup, you can install them by:


CentOS 6


# yum install epel-release
# rpm -ivh https://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/ius-release-1.0-15.ius.centos6.noarch.rpm
# CentOS 7
# yum install epel-release
# rpm -ivh https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-15.ius.centos7.noarch.rpm


Upgrade from MySQL 5.1 to MySQL 5.5


Create a restore point. This will be backing up the databases, the my.cnf, as well as a user and database listing. This can be done by:

# mysql -S mysqldump
# mkdir -p /root/mysqlupgrade/mysql51
# mysql -e 'show databases;' > /root/mysqlupgrade/mysql51/mysql-5.1.databases

# mysql --silent --skip-column-names --execute "select concat('\'',User,'\'@\'',Host,'\'') as User from mysql.user;" | sort | while read u; do echo "-- $u"; mysql --silent --skip-column-names --execute "show grants for $u" | sed 's/$/;/'; done > /root/mysqlupgrade/mysql51/mysql-5.1.grants
# cp /etc/my.cnf /root/mysqlupgrade/mysql51/mysql-5.1.cnf.orig
# yum install xz
# mysqldump --routines --all-databases | xz > /root/mysqlupgrade/mysql51/mysql-5.1.dump.sql.xz


Now stop MySQL and upgrade it to MySQL 5.5:

# service mysqld stop
# yum --disableexcludes=all shell
remove mysql mysql-server mysql-libs
install mysql55 mysql55-server mysql55-libs mysqlclient16
ts solve
ts run
exit




Generate a version of the my.cnf that is valid for MySQL 5.5. Some options get deprecated or changed between versions, so it is important that this is not skipped. To help with this, we’ll be using dbsake as shown below:

# wget -O /root/mysqlupgrade/dbsake http://get.dbsake.net; chmod u+x /root/mysqlupgrade/dbsake
# /root/mysqlupgrade/dbsake upgrade-mycnf --config /root/mysqlupgrade/mysql51/mysql-5.1.cnf.orig --target 5.5 > /root/mysqlupgrade/mysql-5.5.cnf
# mv /etc/my.cnf /etc/mysql-5.5.cnf.orig
# mv -f /root/mysqlupgrade/mysql-5.5.cnf /etc/my.cnf


Start MySQL without the grant tables to verify it is running MySQL 5.5 and all the databases loaded:

# sed -i 's/\[mysqld\]/[mysqld]\nskip-grant-tables\nskip-networking/' /etc/my.cnf
# service mysqld start
# mysql -sse "select @@version"
# mysql -e "show databases;" > /root/mysqlupgrade/mysql51/mysql-5.5.databases
# diff -U0 /root/mysqlupgrade/mysql51/mysql-5.1.databases /root/mysqlupgrade/mysql51/mysql-5.5.databases


Now update the database schema. If mysql_upgrade says that a table needs to repaired, repair it with mysqlcheck -A before moving on:

# mysql_upgrade
# sed -i '/\(skip-grant-tables\|skip-networking\)/d' /etc/my.cnf
# service mysqld restart


Finally, confirm MySQL is running version 5.5:
# mysqladmin version


Upgrade from MySQL 5.5 to MySQL 5.6

Create a restore point. This will be backing up the databases, the my.cnf, as well as a user and database listing. This can be done by:



# mysql -S mysqldump
# mkdir -p /root/mysqlupgrade/mysql55
# mysql -e 'show databases;' > /root/mysqlupgrade/mysql55/mysql-5.5.databases
# mysql --silent --skip-column-names --execute "select concat('\'',User,'\'@\'',Host,'\'') as User from mysql.user;" | sort | while read u; do echo "-- $u"; mysql --silent --skip-column-names --execute "show grants for $u" | sed 's/$/;/'; done > /root/mysqlupgrade/mysql55/mysql-5.5.grants
# cp /etc/my.cnf /root/mysqlupgrade/mysql55/mysql-5.5.cnf.orig
# yum install xz
# mysqldump --routines --all-databases | xz > /root/mysqlupgrade/mysql55/mysql-5.5.dump.sql.xz


Now stop MySQL and upgrade it to MySQL 5.6:

# service mysqld stop
# yum --disableexcludes=all shell
remove mysql55 mysql55-server mysql55-libs
install mysql56u mysql56u-server mysql56u-libs mysqlclient16
ts solve
ts run
exit


Generate a version of the my.cnf that is valid for MySQL 5.6. Some options get deprecated or changed between versions, so it is important that this is not skipped. To help with this, we’ll be using dbsake as shown below:

# wget -O /root/mysqlupgrade/dbsake http://get.dbsake.net; chmod u+x /root/mysqlupgrade/dbsake
# /root/mysqlupgrade/dbsake upgrade-mycnf --config /root/mysqlupgrade/mysql55/mysql-5.5.cnf.orig --target 5.6 > /root/mysqlupgrade/mysql-5.6.cnf
# mv -f /root/mysqlupgrade/mysql-5.6.cnf /etc/my.cnf


Start MySQL without the grant tables to verify it is running MySQL 5.6 and all the databases loaded:

# sed -i 's/\[mysqld\]/[mysqld]\nskip-grant-tables\nskip-networking/' /etc/my.cnf
# service mysqld start
# mysql -sse "select @@version"
# mysql -e "show databases;" > /root/mysqlupgrade/mysql55/mysql-5.6.databases
# diff -U0 /root/mysqlupgrade/mysql55/mysql-5.5.databases /root/mysqlupgrade/mysql55/mysql-5.6.databases

Now update the database schema. If mysql_upgrade says that a table needs to repaired, repair it with mysqlcheck -A before moving on:

# mysql_upgrade
# sed -i '/\(skip-grant-tables\|skip-networking\)/d' /etc/my.cnf
# service mysqld restart

Finally, confirm MySQL is running version 5.6:

# mysqladmin version

Upgrade from MySQL 5.6 to MySQL 5.7

Create a restore point. This will be backing up the databases, the my.cnf, as well as a user and database listing. This can be done by:



# mysql -S mysqldump
# mkdir -p /root/mysqlupgrade/mysql56
# mysql -e 'show databases;' > /root/mysqlupgrade/mysql56/mysql-5.6.databases
# mysql --silent --skip-column-names --execute "select concat('\'',User,'\'@\'',Host,'\'') as User from mysql.user;" | sort | while read u; do echo "-- $u"; mysql --silent --skip-column-names --execute "show grants for $u" | sed 's/$/;/'; done > /root/mysqlupgrade/mysql56/mysql-5.6.grants
# cp /etc/my.cnf /root/mysqlupgrade/mysql56/mysql-5.6.cnf.orig
# yum install xz
# mysqldump --routines --all-databases | xz > /root/mysqlupgrade/mysql56/mysql-5.6.dump.sql.xz


Now stop MySQL and upgrade to MySQL 5.7:

# service mysqld stop
# yum --disableexcludes=all shell
remove mysql56u mysql56u-server mysql56u-libs mysql56u-common
install mysql57u mysql57u-server mysql57u-libs mysqlclient16
ts solve
ts run
exit




Generate a version of the my.cnf that is valid for MySQL 5.7. Some options get deprecated or changed between versions, so it is important that this is not skipped. To help with this, we’ll be using dbsake as shown below:

# wget -O /root/mysqlupgrade/dbsake http://get.dbsake.net; chmod u+x /root/mysqlupgrade/dbsake
# /root/mysqlupgrade/dbsake upgrade-mycnf --config /root/mysqlupgrade/mysql56/mysql-5.6.cnf.orig --target 5.7 > /root/mysqlupgrade/mysql-5.7.cnf
# mv -f /root/mysqlupgrade/mysql-5.7.cnf /etc/my.cnf


Start MySQL without the grant tables to verify it is running MySQL 5.6 and all the databases loaded:
# sed -i 's/\[mysqld\]/[mysqld]\nskip-grant-tables\nskip-networking/' /etc/my.cnf
# service mysqld start
# mysql -sse "select @@version"
# mysql -e "show databases;" > /root/mysqlupgrade/mysql56/mysql-5.7.databases
# diff -U0 /root/mysqlupgrade/mysql56/mysql-5.6.databases /root/mysqlupgrade/mysql56/mysql-5.7.databases

If MySQL fails to start, check the logs as it may be due to MySQL looking for a /var/lib/mysqltmp directory. You can verify and correct it by:

# cat /var/log/mysqld.log |grep ERROR
[ERROR] InnoDB: Unable to create temporary file; errno: 2

# cat /etc/my.cnf |grep tmpdir
tmpdir                          = /var/lib/mysqltmp

# mkdir /var/lib/mysqltmp
# chown mysql:mysql /var/lib/mysqltmp
# service mysqld start


Now update the database schema. If mysql_upgrade says that a table needs to repaired, repair it with mysqlcheck -A before moving on:

# mysql_upgrade
# sed -i '/\(skip-grant-tables\|skip-networking\)/d' /etc/my.cnf
# service mysqld restart


Finally, confirm MySQL is running version 5.7:

# mysqladmin version

Rollback plan
What happens if you need to roll back? If you followed the instructions in this article to create the backups, restoration is simple. Just keep in mind that you also need to restore the databases themselves from the original backups. So anything that changed in the database since the upgrade will be lost. If this is not acceptable, do not use these rollback instructions!
It is going to be assumed that you are going to roll all the way back from MySQL 5.7 to MySQL 5.1. Simply adjust the instructions below accordingly if you are going to roll back to a different version.
Stop MySQL and rollback to MySQL 5.1 by:

# service mysqld stop

# yum --disableexcludes=all shell
remove mysql*
install mysql mysql-server mysql-libs mysqlclient16
ts solve
ts run
exit




Restore the original /etc/my.cnf by:

# cp /root/mysqlupgrade/mysql51/mysql-5.1.cnf.orig /etc/my.cnf


Startup MySQL and restore the 5.1-formatted databases:

# mv /var/lib/mysql /var/lib/mysql.bak
# mkdir /var/lib/mysql
# chown mysql:mysql /var/lib/mysql
# service mysqld start
# mysql_secure_installation
# unxz -c /root/mysqlupgrade/mysql51/mysql-5.1.dump.sql.xz | mysql
# service mysqld restart
# mysqladmin version

Comments

Popular posts from this blog

How to Speedup your WordPress site with Amazon CloudFront.

Introduction A WordPress performance is quite excellent . The number of WordPress plugins to handle performance is such evidence. But the easiest way to improve your user experience is to accelerate the entire WordPress website using CloudFront. This will help you not only improve site response time reduces the necessary infrastructure, reducing the load on the Web server, so you can reduce the total cost of the infrastructure works WordPress. CloudFront is actually a site can greatly help your site to respond to unexpected load when gained popularity. Today this post is to clarify the method of providing a reasonable standard configuration on the WordPress website or blog. How does CloudFront help? Amazon CloudFront is to improve the user's experience accessing the Web site in several ways: 1.  Anycast DNS is to ensure that customers are routed to the nearest edge location. 2.  The cached content is available to users at the edge position (i

Linux System : Free Employee Monitoring with Automatic Screenshots

Introduction :   A utomatic screen-shots  of Linux system directly import  on your web server with Linux samba server service and scrot command. 1)  Setup web panel UI on your web server :   Get web panel PHP/HTML code from Github URL: https://github.com/raj412/Employee-Monitoring-for-Linux-System It’s work in Linux server LAMP environment(no need database for this configuration ) Defult login username password is admin/1234. You can change username/passwrod from login.php file in line number #6 Login Page : Dashboard : Screenshot Page : 2)  Samba server configuration on web server : I.  Install Samba on your server where you setup Linux screenshot log system web panel. sudo apt-get update sudo apt-get install samba II.  Set a password for your user in Samba sudo smbpasswd -a <user_name> III.  Share gallery-images folder from you web panel. This is my web panel gallery-images p

How to control high traffic load on Apache servers : optimization performance of APACHE2 & PHP-FPM

Everyone handle high traffic loads  on Apache server. During down-time they forget to check server memory . Apache not used lot of memory  still server not responding. All time we restart Apache service and all things will start working good. I also faced same issue numerous time and all-time  used same solution : Restart Apache. After lots of research and reading found one solution. In this blog you see step-by-step guide to apache2 performance settings. System environment: Intel(R) Xeon(R) CPU 3.10GHz, 4 cores | 8GB RAM Ubuntu 16.04 Apache2 version using mpm_event PHP FPM (5.6,7.1) First,  Calculate process size : Download : python script file “ps_mem.py” from Github Open this and ps_mem.py file upload on you server :  https://github.com/raj412/ps_mem chmod a+x ps_mem.py sudo python ps_mem.py Output like this:  See here : 12 Apache processes, consuming a total of  35.7MiB, so each Apache process is using roughly 3MiB of RAM. The 42 php-fpm process u