4

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

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.

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.

UPDATE:

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 

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.

UPDATE:

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.

wfbarksdale
  • 7,498
  • 15
  • 65
  • 88

2 Answers2

2

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

EDIT

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

create database cakephp

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;

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'      => ''
    );
}
Ben Ashton
  • 1,385
  • 10
  • 15
  • I did install MySql, I think I might remember giving it a password. Is there somewhere in cake that I need to plug in the password? – wfbarksdale Mar 05 '12 at 22:26
  • 1
    Typically you will enter in your database values in the installation process of cakePHP (you might need to change these values in a configuration file, I haven't done it for ages). To see if your MySQL Server is running, open up a terminal and try accessing it with this command: `mysql -u root -p` – Ben Ashton Mar 05 '12 at 22:42
  • Type 'help' or \h for help mysql> | – wfbarksdale Mar 05 '12 at 22:53
  • 1
    Okay, so MySQL is installed and running. The next thing is to make sure you have configured the database in CakePHP, usually found at `app/config/database.php`. http://book.cakephp.org/2.0/en/development/configuration.html – Ben Ashton Mar 05 '12 at 23:02
  • Thanks, i read though that, but I think i need to create a database first maybe? – wfbarksdale Mar 05 '12 at 23:17
  • Yes, you need to create the database and user/pass. I updated my answer – Ben Ashton Mar 05 '12 at 23:21
  • For my case, my user has access to 127.0.0.1 not to localhost. So when I use 127.0.0.1 I can access the DB, otherwise, if I use localhost I can't connect to DB. – Marwan Salim Dec 06 '18 at 08:13
-1

No, MySQL does not come with OSX, you'll have to install it.

The easiest solution is to use XAMPP instead of compiling/installing MySQL yourself. It will also come with a separate Apache and PHP, if you don't want to mess with the native OSX versions.

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • yeah, I wanted to install my own mysql just for the learning experience. It is actually installed, but for some reason it isn't working. – wfbarksdale Mar 05 '12 at 22:36
  • So, make sure the server is running (look for then 'mysqld' process in Activity Monitor), then setup Cake with the mysql login credentials, and the database name (you need to create a database first). Cake's db configs are at app/config/database.php. – bfavaretto Mar 05 '12 at 22:42