CakePHP Database connection “Mysql” is missing, or

2020-01-27 06:37发布

There have been several other posts about this, but none of the answers seemed to work for me.

When I navigate to the CakePHP page on my local machine, there is one error:

Cake is NOT able to connect to the database. Database connection "Mysql" is missing, or could not be created.

When I run this helpful code in my home.ctp, I get the following response:

Error!: SQLSTATE[42000] [1049] Unknown database 'test'

However, my Users/Ben/Sites/myapp/app/Config/database.php looks like this (I set MAMP to look for the document root in Users/Ben/Sites):

<?php
class DATABASE_CONFIG {

    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'Ben',
        'password' => 'mypass',
        'database' => 'CV',
    );
}

I have created a mysql user called Ben with password mypass and created a database called CV under that. Moreover, I can't find mention of a test database anywhere. Help?

18条回答
走好不送
2楼-- · 2020-01-27 06:44

Try adding the socket:

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
查看更多
我想做一个坏孩纸
3楼-- · 2020-01-27 06:47

You might need to create the table in your php file... Open up phpMyAdmin and check to ensure that they database CV exists.

查看更多
劫难
4楼-- · 2020-01-27 06:49

On Mac, using MAMP as a development platform, for cake the correct solution is using Domingo Casarrubio solution.

Add the unix_socket parameter to your database configurations.

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
查看更多
劳资没心,怎么记你
5楼-- · 2020-01-27 06:49

This error can also be caused if your connecting database user doesn't have the proper privileges. I believe you only need a minimum of INSERT, SELECT, UPDATE, and DELETE.

Always check username/password and the user privileges first since CakePHP will most likely give a vague database connection error for either.

查看更多
混吃等死
6楼-- · 2020-01-27 06:49

I have had this problem since upgrading to OSX Yosemite and inserting following line did the trick for me:

 'unix_socket' => '/tmp/mysql.sock'
查看更多
祖国的老花朵
7楼-- · 2020-01-27 06:51

Because, cake bake use unix socket for connecting to database
so that you need add unix_socket for connection string.
You have to confirm location that store mysql.sock in WAS
Example: in my case i'm using xampp on MACOS 10.11
(edit file Config/database.php)

public $default = array(
  ‘datasource’ => ‘Database/Mysql’,
  ‘persistent’ => false,
  ‘host’ => ‘localhost’,
  ‘login’ => ‘root’,
  ‘password’ => ‘root’,
  ‘database’ => ‘cakephp’,
  ‘encoding’ => ‘utf8’,
  ‘unix_socket’ => ‘/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock’
);

Finally, It's work for me!

查看更多
登录 后发表回答