在 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?

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

问题描述

我目前正在阅读 David Golding 的Beginning CakePHP:从新手到专业人士".有一次,我必须使用 CLI 命令蛋糕烘烤",我会看到欢迎屏幕,但是当我尝试烘烤时,例如我收到以下错误消息的控制器:

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 第 117 行警告:mysql_select_db():在第 122 行的/Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php 中提供的参数不是有效的 MySQL-Link 资源警告:mysql_get_server_info():在第 130 行的/Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php 中提供的参数不是有效的 MySQL-Link 资源警告:mysql_query():在第 154 行的/Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php 中提供的参数不是有效的 MySQL-Link 资源错误:您的数据库没有任何表.

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

class DATABASE_CONFIG {var $default = 数组('司机' =>'mysql','连接' =>'mysql_connect','持久' =>错误的,'host' =>':/Applications/MAMP/tmp/mysql/mysql.sock',//UNIX MySQL-socket'登录' =>'我的用户','密码' =>'my_pass','数据库' =>'博客','前缀' =>'',);}

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

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 第 117 行警告:mysql_select_db():在第 122 行的/Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php 中提供的参数不是有效的 MySQL-Link 资源警告:mysql_get_server_info():在第 130 行的/Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php 中提供的参数不是有效的 MySQL-Link 资源警告:mysql_query():在第 154 行的/Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php 中提供的参数不是有效的 MySQL-Link 资源错误:您的数据库没有任何表.

此外,即使我使用 MAMP 在欢迎屏幕上显示的 UNIX 套接字,当使用此套接字而不是 localhost 时,CakePHP 会丢失数据库连接.

关于如何让烘焙工作有任何想法?

-- 编辑 1 --

谢谢你们帮我解决问题!:)

我在确定 my.cnf 中的何处进行编辑以使 MySQL 侦听 TCP/IP 请求时遇到问题.我能找到提到 TCP/IP 的唯一段落如下:

# 根本不监听 TCP/IP 端口.这可以是一个安全增强,# 如果所有需要连接到 mysqld 的进程都运行在同一台主机上.# 与 mysqld 的所有交互都必须通过 Unix 套接字或命名管道进行.# 请注意,在 Windows 上使用此选项而不启用命名管道#(通过enable-named-pipe"选项)将使mysqld无用!##skip-网络

这让我可以完全关闭 TCP/IP,这与我的意图相反.我不知道如何去做你的建议,如果你能更详细一点,那就太好了.我在这些事情上完全是 n00b :S

注册.连接到本地套接字:我删除了主机参数中的前导冒号,结果相同.

解决方案

从错误来看,它似乎正在尝试连接到实际 IP 地址而不是 UNIX 套接字,请看:

<前>'/Applications/MAMP/tmp/mysql/mysql.sock:3306'

它在套接字上附加了一个端口,这是错误的.

因此,我首先尝试配置 MySQL 以侦听 TCP/IP 请求(编辑 my.cnf 中的相应部分)并尝试提供 127.0.0.1 而不是套接字.

如果您不向下滚动:

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

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.

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.

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.

Any ideas on how I can get bake to work?

-- Edit 1 --

Thank you guys for helping me out! :)

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

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

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

解决方案

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.

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.

In case you won't scroll down:

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天全站免登陆