I was happy when I received a call from one of my customers: "Hello Mattia, how are you? We'd like to add a new feature to our Rails Web App to let users pay for an annual subscription. Are you available to discuss the details?"
You can guess my answer.. "Of course! Let's do that"
2 weeks later I sat down on my computer to start the implementation.
I had already worked on that project - so everything was already set up - and I just needed to launch: rails s
Then I saw this error message on the console:
✗ rails s
/Users/mattiaorfano/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': dlopen(/Users/mattiaorfano/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle, 0x0009): Library not loaded: /opt/homebrew/opt/mysql/lib/libmysqlclient.21.dylib
Referenced from: <E748A2AA-20C9-3078-8838-91C4C0607EB7> /Users/mattiaorfano/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle
Reason: tried: '/opt/homebrew/opt/mysql/lib/libmysqlclient.21.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/mysql/lib/libmysqlclient.21.dylib' (no such file), '/opt/homebrew/opt/mysql/lib/libmysqlclient.21.dylib' (no such file), '/usr/local/lib/libmysqlclient.21.dylib' (no such file), '/usr/lib/libmysqlclient.21.dylib' (no such file, not in dyld cache),
....
WTF?! 😭
Couple of days before I had upgraded to MacOS Sonoma 14 and maybe something with mysql installation went wrong. I checked everything and it seemed to work correctly:
mysql -V
mysql Ver 8.1.0 for macos14.0 on arm64 (Homebrew)
mysql -u root -p
mysql>
I could even use a GUI such as SequelPro.
Yet, my rails app couldn't connect to mysql database.
Mhh. It was that time.
As an experienced software developer, I decided to use my super power: a google search! If you click here, you'll see exactly what I did.
Beyond a variety of nerdy explanations of the possible reasons, the solutions were funny to say the least. Things like: reinstall mysql, create symbolic links in remote folders of your MacOs, copy&run python scripts, etc.
My mom always told me "never take candies from strangers".
So, I read carefully the error message...
Something with mysql2 adapter was not working, and maybe...
I thought "What if the solution is as simple as gem pristine mysql2
?"
Boom! My rails app started working again.
gem pristine basically takes a gem and restores it. It’s like uninstalling and reinstalling the gem, using the new system libraries and configurations of MacOS Sonoma.
Now it's your turn. Do you want to take the direct approach, or waste 2 hours googleing around? Let me know in the comments ;)
Top comments (5)
thank you thank you thank you!
After the first shock, the first perplexity, the undertone of my thoughts was “it’s going to be one of those days again”.
But then your post: instead of a grim expression on my face for hours during Googlemania-try-and-error-odyssey: a radiant smile. 😃 🫶 🙏
goto1
Despite your mom's advice, I will be taking this candy. Thank you!
saved me headache, thank you
yep, that did it. saved some time! thx
Thanks!