問題描述
我有一個 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.php 的第 540 行如下:
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?
有人遇到過類似的錯誤嗎?
Has anyone come across a similar error?
謝謝,
瓊斯
推薦答案
試試在APP/config/database.php中的mysql.sock文件中傳入一個絕對路徑
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.
這篇關于CakePHP:沒有這樣的文件或目錄(嘗試通過 unix:///var/mysql/mysql.sock 連接)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!