Dev environment issue related to MySQL and missing OpenSSL v1.0.0 symlink
I woke up early this morning to get some work done before a call and suddenly my local dev environment stopped working without warning and with seemingly no reason. The root issue was that MySQL wouldn’t work,
/usr/local/opt/openssl/lib/libssl.1.0.0.dylib was not loading.
TL;DR: This may have been related to some automatic cleanup on Homebrew’s part. But regardless, a simple restart sorted it. If this happens again and restarting doesn’t sort it, try uninstalling and reinstalling MySQL.
The rest of the detail is below for posterity if I run in to this in the future.
I woke up early this morning to get some work done before a call. Everything was proceeding A-OK, then suddenly I had a fatal error in my dev environment. The ExpressionEngine site I was working on said
There was a database connection error or a problem with a query. Okaaaay. Went to check a Craft CMS site I’m working on, similar issue:
HTTP 503 – Service Unavailable. So it’s a problem with my whole dev environment, not just the EE site. Weird, because the only thing I did before this happened was reload a page.
I opened up Sequel Pro and tried to connect to my local databases, got the error
MySQL said: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2). So it’s definitely a MySQL issue.
Opened up Terminal and ran
valet restart since that often sorts things out. Restart ran fine, but didn’t fix the issue. Then I tried running
mysql.server start and got this error:
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /usr/local/Cellar/mysql/8.0.16/bin/my_print_defaults Reason: image not found Starting MySQL .dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /usr/local/Cellar/mysql/8.0.16/bin/my_print_defaults Reason: image not found dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /usr/local/Cellar/mysql/8.0.16/bin/my_print_defaults Reason: image not found /usr/local/Cellar/mysql/8.0.16/bin/mysqld_safe: line 199: 77549 Abort trap: 6 env MYSQLD_PARENT_PID=77462 nohup /usr/local/Cellar/mysql/8.0.16/bin/mysqld --basedir=/usr/local/Cellar/mysql/8.0.16 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/8.0.16/lib/plugin --log-error=computername.local.err --pid-file=/usr/local/var/mysql/computername.local.pid < /dev/null >> /usr/local/var/mysql/computername.local.err 2>&1 ERROR! The server quit without updating PID file (/usr/local/var/mysql/computername.local.pid).
Finally getting somewhere, maybe.
mysql -u root -p to try to connect and got a similar, simpler error:
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /usr/local/bin/mysql Reason: image not found Abort trap: 6
So the problem seems very tied to OpenSSL v1.0.0. I tried to change directories to
/usr/local/opt/openssl/lib/ to check on things. Lo and behold,
libssl.1.0.0.dylib is missing.
libssl.1.1.dylib is present though.
Did some searching online which suggested running
brew doctor probably should have done that earlier. Ran it, and this warning appeared:
Warning: Broken symlinks were found. Remove them with `brew cleanup`: /usr/local/lib/libcrypto.1.0.0.dylib /usr/local/lib/libssl.1.0.0.dylib
Which makes sense considering the errors I was running in to earlier.
brew cleanup to remove the symlinks, now the problem is that I need to get OpenSSL back in place.
If I run
brew info openssl I see that v1.1.1i is in use. When I run
ls -aln /usr/local/Cellar/openssl* to check which files are present, I can see that the file for v1.1.1i is the only one there, so this makes sense. But AFAIK, I need to install v1.0.0 so that it is compatible with my installation MySQL.
Now in this case, a lot of guidance online suggests running
brew switch openssl 1.0.2r or something similar to get an older version hooked up, but
switch is no longer a valid Homebrew command. There’s a slightly salty convo about it here if you’re interested in context.
At any rate, at this point I finally came across issue #917 in the laravel/valet GitHub repo from a little over a year ago. This person ran in to a very similar issue. Suggestion was to restart and uninstall+install MySQL, with @drbyte providing a compelling reason why this should work to fix the mysql/openssl mismatch.
I restarted my computer, and that was enough to sort the issue, didn’t even have to reinstall MySQL. Should have done that first-thing. 🤦🏻♀️
I think the root cause of the issue is that Homebrew periodically removes deprecated packages. But this is just based on a random comment I found online, I don’t quite understand if this happens automatically or only as part of
brew cleanup. In my case, it would make a lot more sense if it happens automatically since this issue occurred literally out of nowhere. But who knows, I don’t want to spend more time on this.