Edit 2021-02-21: I've confirmed this solution works with both heroku-18 and heroku-20 stacks.
What follows is my solution for having mysql2
gem compiled and working against MySQL v5.7 (rather than v8+) on the heroku-20
stack. This is how I've managed to make it work:
- Add the apt buildstack ahead of your standard buildpack (in my case, that's Ruby):
$ heroku buildpacks:add --index 1 heroku-community/apt
- Create an
Aptfile
in the root of your project, and add the MySQL 5.7 client tools (as a URL for the deb file) to it:
# in Aptfile:
https://cdn.mysql.com/Downloads/MySQL-5.7/libmysqlclient-dev_5.7.32-1ubuntu18.04_amd64.deb
- Ensure that the
mysql2
gem compiles using the Apt-provided library (viaBUNDLE_BUILD__MYSQL2
) and that, when the library loads, it knows how to find libstdc++ (viaLD_PRELOAD
). I've found thatLD_PRELOAD
isn't already set to anything in my apps - but yours may be different, so do check before running this command.
$ heroku config:set \
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
BUNDLE_BUILD__MYSQL2=--with-mysql-config
- Update your app to use the
heroku-20
stack if you haven't already:
$ heroku stack:set heroku-20
- Deploy this Aptfile to your app, and it should work. If the gems are cached from a previous build (for example, if you had already changed the stack and deployed other changes), you will need to clear your build cache prior to deploying, to ensure the
mysql2
gem is recompiled.
If anyone has any questions or thoughts about this, do let me know.
Hi Pat,
We've a container-stack based Rails Heroku app, and our CI is heroku-16 stack. I've followed the instructions here, set the stack in
app.json
toheroku-20
for the test env (triedheroku-18
at some point as well) and set theLD_PRELOAD
&BUNDLE_BUILD__MYSQL2
ENV variables (inapp.json
for test env). While the test setup phase is going fine over the CI, some Thinking Sphinx tests are now failing and I'm not sure why. I should mention we've inherited this app and our team has small-to-none experience working with TS, so we've no idea where to look for more exactly. Here's more info:Tried specifying the engine/version, tests still fail. They passed before doing this update.
I've no idea where to look at this point, so what I guess I'm looking for are some directions, please. Thanks!