CakePHP:没有这样的文件或目录(尝试通过unix:///var/mysql/mysql.sock连接) [英] CakePHP: No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)

查看:199
本文介绍了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.

这篇关于CakePHP:没有这样的文件或目录(尝试通过unix:///var/mysql/mysql.sock连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆