Raspberry Pi: Installing MySQL 5.7 on Raspbian Jessie
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 April 2017) was running MySQL 5.5.52, but I needed 5.7+ for the JSON data-type.
Warning! These instructions will not work on Raspberry Pi Models A, A+, B, B+, Compute Module 1, Zero, or Zero W!
The Debian armhf packages used only support ARMv7 and later, as found in newer Raspberry Pi hardware.
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:
Note: the file names may change slightly in future when packages are updated. If you’re having trouble downloading these packages, point your web browser to the FTP directory (http://ftp.debian.org/debian/pool/main/m/) and check for a newer version (i.e. …_5.7.22-1_armhf.deb instead of …_5.7.21-1_armhf.deb, or similar).
wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.21-1_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient20_5.7.21-1_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqld-dev_5.7.21-1_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-5.7_5.7.21-1_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-core-5.7_5.7.21-1_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-5.7_5.7.21-1_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-core-5.7_5.7.21-1_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mecab/libmecab2_0.996-5_armhf.deb wget http://ftp.debian.org/debian/pool/main/m/mysql-defaults/mysql-common_5.8+1.0.4_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', then Ctrl+O, Ctrl+X to save and exit nano). sudo apt-get update sudo apt-get install gcc-6 g++-6 (this will download and install ~51MB of archives). sudo nano /etc/apt/sources.list (change 'stretch' back to 'jessie', then Ctrl+O, Ctrl+X to save and exit nano). sudo apt-get update
Install required libraries:
sudo dpkg -i libmecab2_0.996-5_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.4_all.deb sudo dpkg -i mysql-client-core-5.7_5.7.21-1_armhf.deb sudo dpkg -i mysql-client-5.7_5.7.21-1_armhf.deb sudo dpkg -i mysql-server-core-5.7_5.7.21-1_armhf.deb sudo dpkg -i mysql-server-5.7_5.7.21-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.
User lbnlrnt commented below that phpmyadmin also needs updating to 4.6 for the new JSON format, so let’s do that:
sudo nano /etc/apt/sources.list (change 'jessie' to 'stretch', then Ctrl+O, Ctrl+X to save and exit nano). sudo apt-get update sudo apt-get install phpmyadmin sudo nano /etc/apt/sources.list (change 'stretch' back to 'jessie', then Ctrl+O, Ctrl+X to save and exit nano). sudo apt-get update
After doing this update phpMyAdmin was just loading a completely blank page. The fix was to clear the PHP session data like this:
sudo rm -rf /var/lib/php5/sessions/*
Now phpMyAdmin loads and I can log in! 🙂 There are two messages in the footer.
The first is: The secret passphrase in configuration (blowfish_secret) is too short.
This is because the newer phpMyAdmin wants a longer secret for security than the older version we just updated. This is an easy fix by modifying the secret like this:
sudo nano /var/lib/phpmyadmin/blowfish_secret.inc.php
Then change the secret to a 32 character long random secret (I did this using a password generator).
$cfg['blowfish_secret'] = '32-random-characters-here-please';
The second message is: Your PHP MySQL library version 5.5.55 differs from your MySQL server version 5.7.18. This may cause unpredictable behavior.
The way I solved this was to manually install the package like this:
cd ~/mysql wget http://ftp.debian.org/debian/pool/main/p/php5/php5-mysqlnd_5.6.33+dfsg-0+deb8u1_armhf.deb sudo dpkg -i php5-mysqlnd_5.6.33+dfsg-0+deb8u1_armhf.deb sudo service apache2 restart
Reload phpMyAdmin in your browser and both messages should be gone, and everything good! 🙂
None of the files exist at the location given as of today:
$ wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.17-1_armhf.deb
–2017-06-29 17:50:52– http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.17-1_armhf.deb
Resolving http://ftp.debian.org... 184.108.40.206, 2001:610:1908:b000::148:12
Connecting to http://ftp.debian.org|220.127.116.11|:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2017-06-29 17:50:53 ERROR 404: Not Found.
How did you find them
Nevermind. It was upgraded:
Yeah, they update the package version/name from time to time. Glad you found it.
Note to anyone in future: To find the latest package available, go to http://ftp.debian.org/debian/pool/main/m/mysql-5.7/ and search (Ctrl+F) for the missing package. Then substitute this file name in the instructions provided in this blog.
For lazy boys, a good’old ctrl+C ctrl+V with 18 instead of 17
sudo dpkg -i mysql-common_5.8+1.0.2_all.deb
sudo dpkg -i mysql-client-core-5.7_5.7.18-1_armhf.deb
sudo dpkg -i mysql-client-5.7_5.7.18-1_armhf.deb
sudo dpkg -i mysql-server-core-5.7_5.7.18-1_armhf.deb
sudo dpkg -i mysql-server-5.7_5.7.18-1_armhf.deb
Well, It seem like I broke “apt” with this.
After “Install required libraries:” part, “apt-get” command do nothing. “remove” remove nothing and “update” do nothing, no error message, just nothing.
Any idea ?
I force the next step by removing “mysql-server” with “dpkg -r”, now “mysql_upgrade -u root -p –force” throw a nice “Segmentation fault”.
And “apt” still doesn’t work.
I feel like I messed up ><
Yeah I just had the same problem on another Raspberry Pi, and realised it’s because I have an old Mobel B+ which is old ARMv6 architecture. The Debian armhf packages used in these instructions only support ARMv7 and later!
I’ve added a warning to the top of this page since discovering the issue. Thanks for the feedback.
Hi ! Good tuto every thing went pretty well !
I’m pretty noob to linux world, command line and all these things
so two things:
-your tuto is good cause I succeed to do it
-it will excuse me from the following question which I’m perhaps really close to the response
The problem :
I have now mysql 5.7 running,
phpmyadmin is working (as you said too) but its version (under jessie / raspbian) don’t manage JSON and this is
the thing I wanted by running 5.7 mysql.
So far, I resolved this by using your way of pimping source.list :
(stretch is using phpmyadmin 4.6 witch manage json …) :
sudo nano /etc/apt/sources.list
(change jessie to stretch)
apt-get install phpmyadmin
sudo nano /etc/apt/sources.list
(back to jessie..)
Here we are, if you need it, it is perhaps the first step to get it BUT read what’s next:
in phpmyadmin’s home page the following message is displayed (already before that in fact):
“Your PHP MySQL library version 5.5.53 differs from your MySQL server version 5.7.18. This may cause unpredictable behavior.”
And I don’t really know how to do that update. ( I didn’t tried in fact if it’s working or not)
I understood, it is php plugin which is not up to date (e g MySQL Client Library ?? )
After some search I found this, I guess it is the way:
unfortunally in usr/bin there is no mysql_config in my rPi
so once again, some search:
I tried the first answer (even I was fearing breaking what I did in this tuto) :
sudo apt-get install libmysqlclient-dev
Haha I was fearing for nothing this does not exist anymore. and say
but this package is remplacing :
Now I really fearing, I don’t want to do that I’m pretty sure it will broke what we did.
So I came back here to cry, anyone has an idea how I can do that, I mean having a mysql_config or updating
there is a sub response to the main response in the SO post which say:
“what you can do is you can manually download suitable mysql server precompiled version and extract mysql_config from tar.gz file. put it in your path. all it does is to read my.cnf file.”
But I’m not sure how to do that. I thing it’s kinda what we did, “extracting”?
So sorry for this long text and I’m pretty sure there is many misspell or mistake, I’m not English native speaker so explaining is a bit hard (even in my native language I’m bad x’) )
I hope it is the first step to get the problem resolved, cause I thing this version of mysql would be interesting peoples for JSON support.
Any one else has this problem?
Hope I heard from you guys soon, if I find something new I’ll keep you in touch.
Thanks for the feedback. I’ve discovered some issues on ARMv6 hardware (don’t think this relates to your comment), and I’m looking at improving these instructions.
I’m looking at the phpMyAdmin update now and should have some instructions soon!
I’ve found a way to update the PHP MySQL library. Please see my updated instructions above. 🙂
Thanks, that helps me a lot by running MySQL 5.7 on my raspberry pi 2.
One addition on rpi: You need also the libevent-core-2.1-6_2.1.8-stable-4_armhf.deb
My usb stick died on my rpi 3 a few weeks ago. I have since replaced with a new usb stick and reinstalled the pi using the raspbian stretch lite. Will this guide work to have Mysql 5.7 install with the raspbian stretch? My processor is a ARMv7 btw.
It looks like strech is currently on MySQL version 5.5.9999. Sid (unstable) is finally getting the newer 5.7.21. See here: https://packages.debian.org/search?searchon=names&keywords=mysql-server
I haven’t tried it myself yet, but the above instructions should work. You won’t need to change /etc/apt/sources.list from ‘jessie’ to ‘stretch’ and back again.
I’d be interested in hearing how this goes if you give it a shot. Good luck!
Thanks for the quick reply. Can you provide a link to the exact .deb I need? I am not sure if this
I need for my rpi 3. Thanks!!!
You’ll need to use the armhf (ARM hard float) packages to match the CPU used by the Raspberry Pis.
So in the instructions above, just use ‘…_5.7.21-1_armhf.deb’ for the packages (the ones I have listed are now an old version).
[Thank you admin for the push in the right direction. Feel free to delete my last reply about dependency errors.]
I have successfully installed MySQL 5.7.21 on a Raspbian Stretch. Below are the files needed [version is up-to-date as of 2.24.2018]. The stars below represents the correct version needed and an extra .deb needed for this particular OS.
Install MySQL5.7 on Raspbian Stretch Lite [2017-11-29]:
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.21-1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient20_5.7.21-1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqld-dev_5.7.21-1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-5.7_5.7.21-1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-core-5.7_5.7.21-1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-5.7_5.7.21-1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-core-5.7_5.7.21-1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mecab/libmecab2_0.996-3.1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/l/lz4/liblz4-1_0.0~r131-2+b1_armhf.deb
sudo wget http://ftp.debian.org/debian/pool/main/m/mysql-defaults/mysql-common_5.8+1.0.4_all.deb *
sudo wget http://cdn-fastly.deb.debian.org/debian/pool/main/libe/libevent/libevent-core-2.1-6_2.1.8-stable-4_armhf.deb *
sudo dpkg -i libevent-core-2.1-6_2.1.8-stable-4_armhf.deb
sudo dpkg -i mysql-common_5.8+1.0.4_all.deb
sudo dpkg -i mysql-client-core-5.7_5.7.21-1_armhf.deb
sudo dpkg -i mysql-client-5.7_5.7.21-1_armhf.deb
sudo dpkg -i mysql-server-core-5.7_5.7.21-1_armhf.deb
sudo dpkg -i mysql-server-5.7_5.7.21-1_armhf.deb
Great! Thanks for the update. 🙂
I’ll share these details in a new post for stretch.
I wish to remove the new mysql package from system. I ran this line, but it says the package is not installed.
‘sudo apt-get –purge remove mysql-server’
I successfully installed MySQL 5.7 into a Docker container and run it on Raspberry Pi 3. Details are in my blog post, see [MySQL 5.7 Docker Container for Raspberry Pi using Debian Sid](https://scito.ch/content/mysql-57-docker-container-raspberry-pi-using-debian-sid).
Great! Thanks for sharing 🙂
Thank you for the tutorial. I followed the instruction but were stopped at the mysql-client-core installation ever though I downloaded the latest version of it. “dpkg -i mysql-client-core……” hit an error “mysql-client-core-5.7 depends on libc6 (>=2.28); however version of libc6.armhf on system is 2.24-11+deb9u4”. How can I update the libc6 to 2.28? Please help.
I had no problems setting this up a while back but during recent installations I’ve been getting an issue where I can’t use mysql unless it’s ran as root. I looked into it a little and found that it was most likely due to the mysql user plugin not being set to mysql_native_password. I am wondering if it is possible to fix this during the installation process as opposed to after it has been completed.
I downloaded copies of the mentioned dpkg installed packages, so I will not keep having to search for the latest release. I also have had to install libevent-core-2.1-7, libc6, and libstdc++6 from raspbian bullseye. I use raspbian buster to install libaio1, libaio-dev, and libhtml-template-perl.
On the pi 3B+ I see:
| Host | User |…| plugin | authentication_string |
| localhost | root |…| auth_socket | |
| localhost | mysql.session |…| mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys |…| mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | debian-sys-maint |…| mysql_native_password | *BBC871D022E534172C3896739FCE86B7E9955AF2 |
But on another mysql server I have shows
| Host | User |…| plugin | authentication_string |
| localhost | mysql.infoschema|…| caching_sha2_password|$A$005$THISISACOMBINATIONOFINVALIDSALTANDP…|
| localhost | mysql.session |…| caching_sha2_password| $A$005$THISISACOMBINATIONOFINVALIDSALTANDP…|
| localhost | mysql.sys |…| caching_sha2_password| $A$005$THISISACOMBINATIONOFINVALIDSALTANDP…|
| localhost | root |…| mysql_native_password | |
I figured it out, sorry for the messy reply. It seems the default stretch OS was the problem. I performed a dist-upgrade to raspbian buster and had no issues with mysql once it was set up. There was a dependency issue relating to libgcc-8-dev &/or gcc-8-base when installing libc6 from bullseye, otherwise it was just a smooth and long process.