26 Apr 2017

Raspberry Pi: Installing MySQL 5.7 on Jessie

Source code

Recently I had the need to upgrade MySQL on a Raspberry Pi running the latest standard distribution version of Jessie. I needed to use the JSON data-type as a MySQL field. My Raspberry Pi (as of Arril 2017) was running MySQL 5.5.52, but I needed 5.7+ for the JSON data-type.

I’m providing these steps to upgrade MySQL with minimal commentary. I’m assuming you have some experience with Linux!

Prepare a new directory:

cd ~
mkdir mysql
cd mysql

Download the new MySQL packages:

wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.17-1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient20_5.7.17-1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqld-dev_5.7.17-1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-5.7_5.7.17-1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-core-5.7_5.7.17-1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-5.7_5.7.17-1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-core-5.7_5.7.17-1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mecab/libmecab2_0.996-3.1_armhf.deb
wget http://ftp.debian.org/debian/pool/main/m/mysql-defaults/mysql-common_5.8+1.0.2_all.deb
wget http://ftp.debian.org/debian/pool/main/l/lz4/liblz4-1_0.0~r131-2+b1_armhf.deb

Install some prerequisite libraries:

sudo apt install libaio1 libaio-dev libhtml-template-perl libevent-core-2.0-5

We will need a newer gcc version for the next step, so get that:

sudo nano /etc/apt/sources.list
(change jessie to stretch)

apt-get update
apt-get install gcc-6 g++-6

sudo nano /etc/apt/sources.list
(change stretch back to jessie)

apt-get update

Install required libraries:

sudo dpkg -i libmecab2_0.996-3.1_armhf.deb
sudo dpkg -i liblz4-1_0.0~r131-2+b1_armhf.deb

Remove the old MySQL server:

sudo apt-get --purge remove mysql-server

Install the new MySQL packages:

sudo dpkg -i mysql-common_5.8+1.0.2_all.deb
sudo dpkg -i mysql-client-core-5.7_5.7.17-1_armhf.deb
sudo dpkg -i mysql-client-5.7_5.7.17-1_armhf.deb
sudo dpkg -i mysql-server-core-5.7_5.7.17-1_armhf.deb
sudo dpkg -i mysql-server-5.7_5.7.17-1_armhf.deb
sudo reboot

After a reboot, get MySQL to upgrade and rebuild all database schemas:

mysql_upgrade -u root -p --force
sudo service mysql restart

Alrighty! At this point I had a new MySQL server running that supported JSON data-types. My pre-existing databases were still intact, and phpmyadmin still worked.

Good luck! 🙂

About the Author:

Hardware and software engineer with experience in product development and building automation. Product Manager at NEX Data Management Systems, based out of Brisbane, Australia.

Leave a Reply