CakePHP:没有这样的文件或目录(尝试通过unix:///var/mysql/mysql.sock连接)
我有一个cakephp应用程序运行良好在我的本地机器(mac osx)一段时间,然后偶然我意识到,我不能连接到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.
我收到此错误:
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]
dbo_mysql行540 .php读取:
The line 540 of dbo_mysql.php reads:
$this->connection = mysql_connect($config['host'] . ':' . $config['port'], $config['login'], $config['password'], true);
我检查过,没有//var/mysql/mysql.sock。它实际上是在/tmp/mysql.sock
I've checked, there is no fle //var/mysql/mysql.sock. It's actually in /tmp/mysql.sock
我试图更改我的php.ini.default匹配上面,但它已经设置为查找/ tmp /本地连接。为什么,错误是从哪里来的?
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?
有人遇到类似错误吗?
感谢,
Jonesy
尝试在APP / config / database中传递一个绝对路径mysql.sock文件。 php
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'
);
}
这比在本地连接上通过ip运行更好更快,更快。
This is better than running via an ip for local connection as the socket connection is much, much faster.