Cannot access MySQL in CakePHP

This is my first installation of the framework, and I'm pretty clueless.

I'm on OSX 10.7 and I have a cakephp platform loaded in /Library/WebServer/Documents/cakephp and I was able to load a test page and get rid of some errors and warnings. Now I am trying to solve this problem.

  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 really don't know what to do here. I installed MySQL. Is MySQL PDO installed on OSX by default? or do i need to install this? How can I check if this is installed if this is a problem.

UPDATE:

Mysql PDO driver is included. Also 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 does not appear on my file system. should i create it? or do I want to change this path somewhere?

UPDATE: I think the problem is that I did not actually create the database. I do not want to configure the database.

I think I'll try to figure it out now.

UPDATE:

What finally solved this was that the cake was looking for a Unix socket in the database in /var/mysql/mysql.sock , but mysql used the socket in /tmp/mysql.sock I fixed this by creating a symlink from /var/mysql/mysql.sock to /tmp/mysql.sock .

+4
source share
2 answers

It seems that MySQL itself is not installed, but the PDO libraries are compiled on your web server. I'm not sure how to check this in OSX, but you can try checking this link: http://www.sequelpro.com/docs/Install_MySQL_on_Mac_OS_X

EDIT

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

 create database cakephp 

Then create a new username / password and give them access to this database. Suppose you want to create a cakephp username and cakepass password:

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

Your database.php configuration file should now look like this:

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

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

The easiest solution is to use XAMPP instead of compiling / installing MySQL yourself. It will also ship with separate Apache and PHP if you do not want to interfere with native OSX versions.

0
source

Source: https://habr.com/ru/post/1399888/


All Articles