Downgrade Mysql to 5.6 from 5.7 on Ubuntu 16.04(xenial)

Ubuntu 16.04 only provides packages for MySql 5.7(by default) which has a range of backwards compatibility issues with code written against older MySql versions. for Rails specific see this

Oracle maintains a list of official APT repositories for MySql 5.6, but those repository do not yet support Ubuntu 16.04, However the 15.10 repos will work for 16.04.

Uninstall MySql 5.7 in any exists:

sudo apt remove mysql-client mysql-server mysql-comman libmysqlclient-dev

Check you removed everything

sudo dpkg -l | grep mysql

Purge reminders (e.g. merged with rc) with

sudo dkpg P <package> [<package>]

Download the apt_config-debain package from Oracle and install it

sudo dpkg -i mysql-apt-config_0.8.0-1_all.deb

Choose “MySQL 5.6” and RUN

sudo apt-cache policy mysql-server

If this shows a 5.6 version, continue.

If not, check your /etc/apt/sources.list.d/mysql.list. It should look roughly like this:


### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may Ubuntu 16.04 only provides packages for MySQL 5.7 which has a range of backwards
# compatibility issues with code written against older MySQL versions.comment out entries
# below, but any other modifications may be lost.
# Use command 'dpkg-reconfigure mysql-apt-config' as root for modifications.
deb http://repo.mysql.com/apt/ubuntu/ wily mysql-apt-config
deb http://repo.mysql.com/apt/ubuntu/ wily mysql-5.6
deb http://repo.mysql.com/apt//ubuntu/ wily mysql-tools
deb-src http://repo.mysql.com/apt/ubuntu/ wily mysql-5.6
### You might have to replace "xenial" with "wily". Although you are using 16.04 (codename Xenial),
### Oracle currently seems to only provide 5.6 in the repos for 14.04 (codename Wiley). But
###  those sources work for 16.04, too.

Create a file /etc/apt/preferences.d/mysql with this content

Package: *
Pin: origin "repo.mysql.com"
Pin-Priority: 999

Run

sudo apt-get update

Now recipe’s run should provide

sudo apt install mysql-client mysql-server libmysqlclient-dev

You should get 5.6 versions. Extra Things I learned : Use P(purge), dpkg -l. Cheers :)

Avatar
Rajeev Sharma
Technical Lead

software entrepreneur and father of a fairy tale!!!.