2025 still running into this cryptic error message:
Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)")
I had 2 cloud run functions connecting to the same SQL instance, one working and the other getting that error message. The code was literally copy-paste from the working to the not-working.
The above link from @Josh Bloom gave me the idea to contrast "gcloud run services describe x" output and, sure enough, the working service had a "SQL connection" defined and the other didn't. I added the missing connection in the console and the bad guy started working.
What gives? I generated both these cloud run functions from the same laptop, with the same "gcloud functions deploy" and the same exact code copy-pasted.