cakephp mysql sock连接,CakePHP:没有这样的文件或目录(尝试通过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

解决方案

Try passing an absolute path the the mysql.sock file in the APP/config/database.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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值