如何在Mac OSX上使用MAMP时,如何获取CakePHP烘焙以查找mysql.sock并识别MySQL? [英] How do I get CakePHP bake to find mysql.sock and recognize MySQL while using MAMP on Mac OSX?

查看:303
本文介绍了如何在Mac OSX上使用MAMP时,如何获取CakePHP烘焙以查找mysql.sock并识别MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在读开始CakePHP:从新手到专业,David Golding。有一点我必须使用CLI命令蛋糕烘烤,我得到欢迎屏幕,但当我尝试烘烤。 a Controller我得到以下错误消息:

I am currently reading "Beginning CakePHP:From Novice to Professional" by David Golding. At one point I have to use the CLI-command "cake bake", I get the welcome-screen but when I try to bake e.g. a Controller I get the following error messages:

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 117

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 122

Warning: mysql_get_server_info(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 130

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 154
Error: Your database does not have any tables.

我怀疑错误消息与php试图访问错误的mysql套接字,即默认的osx mysql-socket - 而不是MAMP使用的那个。因此,我更改我的数据库配置以连接到UNIX mysql-socket(:/Applications/MAMP/tmp/mysql/mysql.sock):

I suspect that the error-messages has to do with php trying to access the wrong mysql-socket, namely the default osx mysql-socket - instead of the one that MAMP uses. Hence I change my database configurations to connect to the UNIX mysql-socket (:/Applications/MAMP/tmp/mysql/mysql.sock):

class DATABASE_CONFIG {

    var $default = array(
        'driver' => 'mysql',
        'connect' => 'mysql_connect',
        'persistent' => false,
        'host' =>':/Applications/MAMP/tmp/mysql/mysql.sock', // UNIX MySQL-socket
        'login' => 'my_user',
        'password' => 'my_pass',
        'database' => 'blog',
        'prefix' => '',
    );

}

但我得到相同的错误消息与新套接字:

But I get the same error-messages with the new socket:

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock:3306' (2) in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 117

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 122

Warning: mysql_get_server_info(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 130

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 154
Error: Your database does not have any tables.

此外,即使我使用MAMP显示在其欢迎屏幕上的UNIX套接字,CakePHP丢失

Also, even though I use the UNIX-socket that MAMP show on it's welcome-screen, CakePHP loses the database-connection, when using this socket instead of localhost.

有关如何让bake工作的任何想法?

Any ideas on how I can get bake to work?

- 编辑1 -

感谢您帮助我! :)

我有一个问题,找出my.cnf中的哪里编辑,让MySQL收听TCP / IP请求。我可以找到TCP / IP提到的唯一段落如下:

I have a problem figuring out where in my.cnf to edit to get MySQL to listen to TCP/IP request. The only paragraph I can find where TCP/IP is mentioned is the following:

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
#skip-networking

IP完全,这是我的意图的相反。我不知道如何去你的建议,如果你可以更精心,这将是巨大的。我对这些事项总共n00b:S

That allows me to turn off TCP/IP completely, which is the opposite of my intention. I don't know how to go about what you suggest, if you could be more elaborate it would be great. I am a total n00b on these matters :S

注册。连接到本地套接字:我删除了host-parameter中的冒号,结果相同。

Reg. connecting to a local socket: I removed the leading colon in the host-parameter, same result.

推荐答案

看起来像是试图连接到一个实际的IP地址,而不是一个UNIX套接字,看起来:

From the error, it looks like it's trying to connect to an actual IP address and not a UNIX socket, look:


 '/Applications/MAMP/tmp/mysql/mysql.sock:3306'

它将一个端口附加到套接字,这是错误的。

It's appending a port to the socket, which is wrong.

所以,我首先尝试配置MySQL监听TCP / IP请求(编辑my.cnf中的正确部分),并尝试提供127.0.0.1而不是套接字。

So, I'd first try to configure MySQL to listen to TCP/IP requests (edit the proper section in my.cnf) and try providing 127.0.0.1 instead of the socket.

如果无法向下滚动

要在CakePHP级别上修复它,请将database.php上的主机更改为localhost,并添加一个将其值设置为套接字名称的端口指令'/Applications/MAMP/tmp/mysql/mysql.sock '

To fix it at CakePHP level, change host on database.php to 'localhost' and add a port directive with its value set to the socket name '/Applications/MAMP/tmp/mysql/mysql.sock'

这篇关于如何在Mac OSX上使用MAMP时,如何获取CakePHP烘焙以查找mysql.sock并识别MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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