I have now a new MabBook with 10.8 and I am trying to set up all the Apache&MySQL etc. Apache successfully runs including vhosts.
in my /etc/hosts I have all the local hosts set including 127.0.0.1 localhost etc.
when I try to coennct to one of my local vhost, e.g. alpensonne, I can connect to MySQL without any troubles. if I try to have the MySQL host to be localhost, I get the follwoing error:
Database connection error (2): Could not connect to MySQL.
I know the error(2) means username or password incorrect, but they are fine. If I connect with
mysql -u root
SELECT password,host FROM user where user='root';
also I have just done to be double sure:
SET PASSWORD FOR 'root'@'localhost' = '';
Is it possible that localhost uses a different mysql socket? maybe it then tries to connect to a different mysql?
I hope someone can help me.
Ok I found the mistake... The problam was, that I have forgot to change the php.ini file to point to the mysql.default_socket... My default_socket was set to /var/mysql/mysql.sock so I just created a symlink to /tmp/mysql.sock and now all works fine! :)
@shadyyx Thanks for the proposal of MAMP, I know this of course but not such a big fan of MAMP, XAMPP, LAMP etc. for windows user its good so you can use apache instead of IIS, but for Linux, Unix and also Mac user you can use the build in apache server... so no need to use an other third party software. also you are depended then on the php version etc. I like it more to be able to configure it myself.
With MySQL from MacPorts it works with this path:
mysql.default_socket = /opt/local/var/run/mysql56/mysqld.sock
To elaborate on the answer from @schurtertom...
The problem is that mysql.default_socket
setting in PHP.INI defaults to a different location than where MySQL actually puts that file.
Instead of editing the config files, create an alias in the location that PHP is looking that connects to the real mysql.sock by running these two commands (no restart needed):
mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock