This is a story of how someone on the other side of the world who you’ve never met can completely ruin your day.
I do my accounts on my own OSX machine where I’ve installed MySQL. It comes, of course, with the Apache web server, and the scripting language PHP; so with a bit of hacking about some time ago (a couple of years at least) I got it all running. Key in making it feasible to manipulate MySQL was the excellent, free and open-source CocoaMySQL.
So anyway. I’d set up a system where I could keep my accounts: I’d created some pages and linked databases which I could access via my local server, so that I know where I am with payments, expenses, and money owed for taxes moved to savings accounts. Plus the Apache/MySQL/PHP combo is excellent for testing WordPress upgrades without inflicting them on the wider public.
Then on Wednesday evening I clicked on the page for my accounts. It replied:
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Users/charles/account_mysql_connect.php on line 13
To which you, and I at first, respond: “Unh?” Something’s not working. But what? Apache is OK; I could get other web pages from my local machine. But was it PHP or MySQL that was looking for
mysql.sock in the wrong place? Either MySQL had moved its .sock, or PHP was looking in the wrong place. Either way it wasn’t good, because I don’t like futzing around with config files. Apart from anything else, OSX makes it almost impossible to find them. (I either use the Terminal, or the very good Locator – another free program that will locate pretty much anything on your machine, though from a static database.)
I didn’t know which was doing this wrong, but thought I’d ask Google first. And I recalled that since last using my database, there had been the 10.4.4 update to OSX. So I Googled “10.4.4 MySQL”. The first result it pointed to: MacOSXHints, with Repair PHP/MySQL connections in 10.4.4.
Ah. So Apple had broken something about PHP and MySQL in the update. Gee, thanks, guys. I don’t recall seeing a mention of that in the notes to the update. Not a thing. No questions when I updated like “I see you have MySQL installed, do you want us to …” Well, at that point I didn’t know what I’d want to do.
So I had a read of the MacOSXHints article. Yes, Apple had indeed broken things, by making PHP look for the “socket” (connection) to MySQL in a different place from previously: it now looks in the directory
private/var/mysql/ for the
mysql.sock file. If it doesn’t find it, it blurps. However, the whole idea of that directory and that file is a completely new one introduced in 10.4.4. MySQL normally creates its socket file in
private/etc/. (Apparently, this article at Hivemind explains why the move was needed. Personally, I don’t get it.)
On reading the article, there were clearly two schools of thought for how to cure it. One said: “create a symbolic link [an alias] to the old file in the new directory.” The other (including Apple) said: “That first idea is a bad one – it’s insecure. Instead, make MySQL create its socket in
/var/mysql.” (See the discussion at these files: “Issues connecting PHP to MySQL and “Improvements to Apache/PHP/MySQL interaction”.)
I had a try at the second solution. Wow, what a disaster. MySQL became amazingly unstable and kept falling over: I watched it in the Activity Monitor. The process would last a few seconds, then disappear, then reappear with a different process number. Basically it was crashing and then being lifted again by something, like a drunk being carried by friends and insisting it could handle it. At the same time my internet connection went hazy; pages wouldn’t load. I don’t know if it was associated, as the router could resolve names, and if I put a DNS number rather than a name into a web page, it loaded fine. But I was just frustrated as hell by now; I’d been struggling with this problem for three hours, it was late, and I wanted to have it solved. But I could see there was no way I was going to solve it before tiredness completely overwhelmed me.
So, cursing the people in charge of updates at Apple, I went to bed.
The next day I returned to the fight. My web connection was still unstable; MySQL was still up and down like.. oh, do your own simile. Somehow I got MySQL to stop, by virtue of a couple of complete reboots (which is why my uptime is measured only in a couple of days). Then I looked at its configuration file, and decided to leave well enough alone. Same with PHP: I’m not really going to mess with its config file. No, the simple, and less brain-crushing thing to do was to follow the original advice in the OSXHints article: create a link from the “new” directory to the old one. I did. It worked. Finally, after about six hours of struggling, I was back to where I’d been a week before.
Now tell me: was it necessary that I had to be put through that? OK, so not many people will install MySQL on their machines. But a few will. It would have been nice, to say the very least, if there had been an explanatory note in the OS updates about what was going to happen to the PHP/MySQL link.
Still, my mishaps did give my wife, who has always been suspicious of the idea of trusting one’s financial data to a machine rather than good old paper, the chance to crow. And I had to agree that for once she had a point.
And next time there’s an OS update… I’m going to read the notes about PHP and MySQL very carefully. That’s assuming that they tell us what they’ve done. But what else will be in there that I’ll miss?