Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP: No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)

I have had a cakephp app running fine on my local machine (mac osx) for a while and then suddently I realise that I can't connect to mysql.sock.

I'm getting this error:

Warning (2): mysql_connect() [http://php.net/function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) [CORE/cake/libs/model/datasources/dbo/dbo_mysql.php, line 540]

The line 540 of dbo_mysql.php reads:

$this->connection = mysql_connect($config['host'] . ':' . $config['port'], $config['login'], $config['password'], true);

I've checked, there is no fle //var/mysql/mysql.sock. It's actually in /tmp/mysql.sock

I tried changing my php.ini.default to match the above but it's already set to look in /tmp/ for local connections. Why, and where is the error coming from?

Has anyone come across a similar error?

Thanks,

Jonesy

like image 753
iamjonesy Avatar asked Oct 19 '10 11:10

iamjonesy


3 Answers

Try passing an absolute path the the mysql.sock file in the APP/config/database.php

<?php
    class DATABASE_CONFIG {
        var $default = array(
            'driver' => 'mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'dbUser',
            'password' => 'dbPassword',
            'database' => 'dbName',
            'prefix' => '',
            'port' => '/path/to/mysql.sock'
        );
    }

This is better than running via an ip for local connection as the socket connection is much, much faster.

like image 196
Abba Bryant Avatar answered Nov 20 '22 02:11

Abba Bryant


If you are having problem with CakePHP 2.0, try this:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
like image 36
Milos Matic Avatar answered Nov 20 '22 02:11

Milos Matic


In phpcake 2.0 use 'unix_socket' instead of port

<?php
    class DATABASE_CONFIG {
        var $default = array(
            'datasource' => 'Database/Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'dbUser',
            'password' => 'dbPassword',
            'database' => 'dbName',
            'prefix' => '',
            'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock', //Path for mac XAMPP
        );
    }
like image 6
Kent Widman Avatar answered Nov 20 '22 00:11

Kent Widman