Tag Archives: mysql

Problems connecting to unix:///var/mysql/mysql.sock

In a previous post I talked about MySQL 5.5 and Mac OSX.

In this post I’ll go through fixing the problems with PHP and connecting to your local mysql install, using “localhost”.

The problems began a while back, with lots of errors in my apache error log saying:

[error] [client ::1] PHP Warning:  mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in ...

In the rush I was in, I quickly changed my mysql connection to use: 127.0.0.1, which is the IP of your localhost. So basically the same thing.

Today I’m doing some freelance work for a customer, who has some problems with his server, after the PHP version was upgraded. I decided to fetch all his php files to my local Mac and then run through his webshop, fixing any errors I might see in the log etc.
When starting the my apache and running the website, I quickly found the MySQL connect error again.

Since this project should be a “search and fix” mission, I didn’t have time to change the mysql_connect(xxx) statements in the code (yes yes, not my code, so I didn’t create the mess…), so instead, I wanted to fix my local PHP->MySQL connection.

The fix was relatively easy, and only contains 1 to 2 steps:

Step 1 (if needed)

If you haven’t activated php.ini on your local install, open a Terminal and write the following command:

sudo cp /etc/php.ini.default /etc/php.ini

This copies the default php settings to the php.ini file, which the apache server uses.

Then restart your apache server. (Using System Preferences->Sharing->Web sharing)

Your PHP is now using the php.ini file.

Step 2

Open /etc/php.ini file using your favorite text editor.

Goto line 1216 (or search for “mysql.default_socket = ” without the quotes) and change /var/mysql/mysql.sock to /tmp/mysql.sock

Restart your apache server and you should now be able to connect to localhost again.

Still have problems?

If you still have problems, then try the following:

Open Terminal and write:

mysqladmin version

It should print something like this:

mysqladmin  Ver 8.42 Distrib 5.1.53, for apple-darwin10.3.0 on i386
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version		5.1.53
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/tmp/mysql.sock
Uptime:			2 hours 52 min 6 sec

Threads: 3  Questions: 58  Slow queries: 0  Opens: 16  Flush tables: 1  Open tables: 9  Queries per second avg: 0.5

The path in the UNIX socket is the “localhost” connection point. So go back to Step 2 and use that path instead.

MySQL 5.5, Mac OS X and startup item security error

A few days ago I got a shiny new macbook at work and I needed to install my dev environment again.

I came across a few problems when installing the new MySQL community server package though, which had been upgraded to 5.5 instead of the 5.1 release I had on my old Mac.

Fixing MySQL server startup

The first problem I came across was that the server would not start properly, using the prefpane item.

This is easily fixed by editing the file /usr/local/mysql/support-files/mysql.server and going to line 46 + 47 and replacing the lines there with this:

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

You can now use the prefpane item to start your MySQL server.

source: http://forums.mysql.com/read.php?11,399397,399606#msg-399606

Fixing the autostart

If you are like me, you like it when all the services start at boot, since you don’t have to start ’em by hand.
However, there is a problem with getting MySQL server 5.5 to start using the prefpane.

In order to get the autostart up and running you need to fix the privileges on the startup item.
Open a terminal and do the following:

sudo chown :wheel /Library/StartupItems/MySQLCOM/MySQLCOM 
sudo chown :wheel /Library/StartupItems/MySQLCOM/StartupParameters.plist

After that you need to restart the computer. Logging out and back ind will not do the job.

source: http://bugs.mysql.com/bug.php?id=57790#c350454