我目前正在阅读 David Golding 的“Beginning CakePHP:From Novice to Professional”。有一次我必须使用 CLI 命令“cake bake”,我得到了欢迎屏幕,但是当我尝试烘焙控制器时,我收到以下错误消息:
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使用的那个。因此,我更改了我的数据库配置以连接到 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 套接字,当使用此套接字而不是 localhost 时,CakePHP 也会丢失数据库连接。
关于如何让烘焙工作的任何想法?
-- 编辑 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,这与我的意图相反。我不知道如何去做你的建议,如果你能更详细一点,那就太好了。在这些问题上我完全不知道:S
注册。连接到本地套接字:我删除了主机参数中的前导冒号,结果相同。