在CakePHP中无法使用MySQL [英] Can't get going with MySQL in CakePHP

查看:59
本文介绍了在CakePHP中无法使用MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次安装框架,但我一无所知.

This is my first time installing a framework, and I am pretty clueless.

我在OSX 10.7上,并且将Cakephp框架加载到了/Library/WebServer/Documents/cakephp中,并且能够加载测试页并摆脱了一些错误和警告.现在,我正在尝试解决此问题

I am on OSX 10.7 and I have the cakephp framework loaded into /Library/WebServer/Documents/cakephp and I have been able to load the test page and get rid of some of the errors and warnings. Right now I am trying to resolve this

  Warning (2): PDO::__construct() [pdo.--construct]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) [CORE/Cake/Model/Datasource/Database/Mysql.php, line 160]
  Cake is NOT able to connect to the database.
  Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.

我真的不知道该怎么办.我已经安装了MySQL. MySQL PDO是否默认安装在OSX上?还是我需要安装?如果这似乎是问题,该如何检查是否已安装.

I don't really know what to do here. I have installed MySQL. Does the MySQL PDO come installed on OSX by default? or do I need to install that? How can I check if that is installed if that seems to be the problem.

更新:

PDO Mysql驱动程序已启用. 另外,pro_mysql的phpinfo()看起来像这样:

The PDO Mysql driver is enabled. Also the phpinfo() for pro_mysql looks like this:

 Directive                     Local Value               Master Value
 pdo_mysql.default_socket   /var/mysql/mysql.sock   /var/mysql/mysql.sock 

但是mysql目录没有出现在我的文件系统中.我应该创建它吗?还是我需要在某处更改此路径?

However the mysql directory doesn't appear in my filesystem. should I create it? or do I nee to change this path somewhere?

更新: 我认为问题在于我实际上尚未建立数据库.我有点愚蠢,没有建立数据库.

UPDATE: I think the problem is that I haven't actually set up a database. kindof dumb of me not to set up the database.

我想我现在会设法解决这个问题.

I guess I will try to figure that out now.

更新:

最终解决此问题的是蛋糕正在/var/mysql/mysql.sock中寻找数据库的Unix套接字,但是mysql在/tmp/mysql.sock中使用了套接字 我通过创建从/var/mysql/mysql.sock/tmp/mysql.sock的符号链接来解决此问题.

The thing that finally solved this was that cake was looking for the Unix socket to the database in /var/mysql/mysql.sock but mysql was using the socket in /tmp/mysql.sock I fixed this by creating a symbolic link from the /var/mysql/mysql.sock to /tmp/mysql.sock.

推荐答案

看起来好像没有安装MySQL本身,但是PDO库是使用您的Web服务器编译的.我不确定如何在OSX中进行检查,但是您可以尝试检查一下此链接: http://www .sequelpro.com/docs/Install_MySQL_on_Mac_OS_X

It looks more like MySQL itself is not installed, but the PDO libraries are compiled with your webserver. I am not sure how to check this in OSX, but you can try checkign this link out: http://www.sequelpro.com/docs/Install_MySQL_on_Mac_OS_X

编辑

登录到MySQL(mysql -u root -p)并创建数据库:

Log into MySQL (mysql -u root -p) and create the databas:

create database cakephp

然后创建一个新的用户名/密码,并授予他们对该数据库的访问权限.假设您要创建用户名cakephp和密码cakepass:

Then create a new username/password and grant them access to this database. Let's say you want to create the username cakephp and the password cakepass:

GRANT ALL ON cakephp.* TO cakephp@localhost IDENTIFIED BY 'cakepass';
FLUSH PRIVILEGES;

现在您的database.php配置文件应如下所示:

And now your database.php config file should look like this:

<?php
class DATABASE_CONFIG {
    public $default = array(
        'datasource'  => 'Database/Mysql',
        'persistent'  => false,
        'host'        => 'localhost',
        'login'       => 'cakephp',
        'password'    => 'cakepass',
        'database'    => 'cakephp',
        'prefix'      => ''
    );
}

这篇关于在CakePHP中无法使用MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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