If your application is not performing as expected, you can always downgrade to a previous GA release (MySQL 5.7). Before downgrading, it is recommended to take a logical backup (refer to Chapter 7, Backups). Note that you can downgrade by only one previous release. Suppose that you want to downgrade from MySQL 8.0 to MySQL 5.6, you have to downgrade to MySQL 5.7, and then from MySQL 5.7 to MySQL 5.6.
You can do it in two ways:
- In-place downgrade (downgrades within MySQL 8)
- Logical downgrade
In the following subsections, you will be learning how to handle the installation/uninstallation/upgrade/downgrade using various repositories, bundles, and so on.
For downgrades between the GA status releases within MySQL 8.0 (note that you cannot downgrade to MySQL 5.7 using this method):
- Shut down the old MySQL version
- Replace the MySQL 8.0 binaries or older binaries
- Restart MySQL on the existing
data directory
- Run the
mysql_upgrade
utility
mysql> SET GLOBAL innodb_fast_shutdown = 0;
- Shut down the
mysql
server as described in the Stopping MySQL 8.0 Server section:
shell> sudo systemctl stop mysqld
- Remove the
InnoDB
redo log files (theib_logfile*
files) from thedata directory
to avoid downgrade issues related to redo log file format changes that may have occurred between releases:
shell> sudo rm -rf /var/lib/mysql/ib_logfile*
- Downgrade MySQL. To downgrade the server, you need to uninstall MySQL 8.0, as described in the Uninstalling MySQL 8 section. The configuration files are automatically stored as backup. List the available versions:
shell> sudo yum list mysql-community-server
Downgrades are tricky; it is better to remove the existing packages before downgrading:
shell> sudo rpm -qa | grep -i mysql-community | xargs sudo rpm -e --nodeps warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
Install the older version:
shell> sudo yum install -y mysql-community-server-<version>
shell> sudo dpkg-reconfigure mysql-apt-config
- Run
apt-get update
:
shell> sudo apt-get update
- Remove the current version:
shell> sudo apt-get remove mysql-community-server mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core -y shell> sudo apt-get autoremove
- Install the older version (autoselected since you have reconfigured):
shell> sudo apt-get install -y mysql-server
Uninstall the existing packages (refer to the Uninstalling MySQL 8 section) and install the new packages, which can be downloaded from the MySQL Downloads
(refer to the Installing MySQL 8.0 using RPMs or DEB files section).
If you have installed MySQL through binaries, you have to remove the symlink to the old version (refer to the Uninstalling MySQL 8 section) and do a fresh installation (refer to the Installing MySQL on Linux Using Generic Binaries section):
- Start the server as described in the Starting or Stopping MySQL 8 section. Please note that the start procedure is the same for all the versions.
- Run the
mysql_upgrade
utility:
shell> sudo mysql_upgrade -u root -p
- Restart the MySQL server to ensure that any changes made to the system tables take effect:
shell> sudo systemctl restart mysqld
Here is an outline of the steps:
- Export existing data from the MySQL 8.0 version using logical backup (refer to Chapter 7, Backups for logical backup methods)
- Install MySQL 5.7
- Load the dump file into the MySQL 5.7 version (refer to Chapter 8, Restoring Data for restoring methods)
- Run the
mysql_upgrade
utility
Here are the detailed steps:
- You need to take logical backup of the database. (refer to Chapter 7, Backups for a quicker backup called
mydumper
):
shell> mysqldump -u root -p --add-drop-table --routines --events --all-databases --force > mysql80.sql
- Shut down the MySQL server as described in the Starting or Stopping MySQL 8 section.
- Move the
data directory
. Instead of restoring the SQL backup (in step 1), we can move back thedata directory
if you want to keep MySQL 8:
shell> sudo mv /var/lib/mysql /var/lib/mysql80
- Downgrade MySQL. To downgrade the server, we need to uninstall MySQL 8. The configuration files are automatically backed up.
After the uninstallation, install the older version:
- Switch the repositories:
shell> sudo yum-config-manager --disable mysql80-community shell> sudo yum-config-manager --enable mysql57-community
- Verify that
mysql57-community
is enabled:
shell> yum repolist enabled | grep "mysql.*-community.*" !mysql-connectors-community/x86_64 MySQL Connectors Community 42 !mysql-tools-community/x86_64 MySQL Tools Community 53 !mysql57-community/x86_64 MySQL 5.7 Community Server 227
- Downgrades are tricky; it is better to remove the existing packages before downgrading:
shell> sudo rpm -qa | grep -i mysql-community | xargs sudo rpm -e --nodeps warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
- List the available versions:
shell> sudo yum list mysql-community-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.rackspace.com * epel: mirrors.develooper.com * extras: centos.s.uw.edu * updates: mirrors.syringanetworks.net Available Packages mysql-community-server.x86_64 5.7.20-1.el7 mysql57-community
- Install MySQL 5.7:
shell> sudo yum install -y mysql-community-server
shell> sudo dpkg-reconfigure mysql-apt-config
- Run
apt-get update
:
shell> sudo apt-get update
- Remove the current version:
shell> sudo apt-get remove mysql-community-server mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core -y shell> sudo apt-get autoremove
- Install MySQL 5.7:
shell> sudo apt-get install -y mysql-server
Uninstall the existing packages (refer to the Uninstalling MySQL 8 section) and install the new packages, which can be downloaded fromMySQL Downloads
(refer to the Installing MySQL 8 using RPM or DEB files section).
If you have installed MySQL through binaries, you have to remove the symlink to the old version (refer to the Uninstalling MySQL 8 section) and do a fresh installation (refer to the Installing MySQL on Linux using Generic Binaries section).
Once you have downgraded MySQL, you have to restore the backup and run the mysql_upgrade
utility:
- Start MySQL (refer to the Starting or Stopping MySQL 8 section). You need to reset the password again.
- Restore the backup (this may take a long time, depending up on the size of backup). Refer to Chapter 8, Restoring Data, for a quick restoration method called
myloader
:
shell> mysql -u root -p < mysql80.sql
- Run
mysql_upgrade
:
shell> mysql_upgrade -u root -p
- Restart the MySQL server to ensure that any changes made to the system tables take effect. Refer to the Starting or Stopping MySQL 8 section:
shell> sudo /etc/init.d/mysql restart