gpt4 book ai didi

php - 在 Mac OSX 上使用 MAMP 时如何让 CakePHP bake 找到 mysql.sock 并识别 MySQL?

转载 作者:可可西里 更新时间:2023-11-01 07:45:45 25 4
gpt4 key购买 nike

我目前正在阅读 David Golding 的“CakePHP 入门:从新手到专业”。有一次我必须使用 CLI 命令“蛋糕烘焙”,我看到了欢迎屏幕,但是当我尝试烘焙时,例如 Controller 我收到以下错误消息:

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-socket 有关,即默认的 osx mysql-socket - 而不是 MAMP 使用的 mysql-socket。因此,我更改了我的数据库配置以连接到 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' => '',
);

}

但是我在使用新套接字时得到了相同的错误消息:

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 也会丢失数据库连接。

关于如何让 bake 工作有什么想法吗?

-- 编辑 1 --

谢谢大家帮助我! :)

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

# 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

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

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

最佳答案

我找到了这个问题的解决方案:在cakephp app/config/database.php 文件中添加套接字配置

class DATABASE_CONFIG {

var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'port' => '/Applications/MAMP/tmp/mysql/mysql.sock', // here is the key !
'login' => 'you',
'password' => 'yourpass',
'database' => 'yourdb',
'prefix' => '',

);

关于php - 在 Mac OSX 上使用 MAMP 时如何让 CakePHP bake 找到 mysql.sock 并识别 MySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/366550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com