CakePHP Database connection “Mysql” is missing, or could not be created

后端 未结 18 1382
暖寄归人
暖寄归人 2020-11-30 11:05

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

相关标签:
18条回答
  • 2020-11-30 11:25

    An alternative to unix_socket (especially for OS X people) is to replace localhost with 127.0.0.1

    Would be as Follows :

    public $default = array(
                    'datasource' => 'Database/Mysql',
                    'persistent' => false,
                    'host' => '127.0.0.1',
                    'login' => 'user',
                    'password' => 'password',
                    'database' => 'database-name',
                    'prefix' => '',
                    'encoding' => 'utf8',
            );
    
    0 讨论(0)
  • 2020-11-30 11:30

    I tried splicing the code from Example 2 of http://php.net/manual/en/pdo.connections.php into /app/View/Pages/home.ctp. I had to fix the arguments the PDO constructor and change the name of the table in the query. The example 2 code returned the error "Error!: could not find driver". Based on King Jk's answer I was attempting to modify the php.ini when I started to wonder where a php_pdo_mysql.so might live. http://php.net/pdo_mysql showed how it was compiled as part of PHP via the --with-pdo-mysql option to configure. Recompiling fixed my problem. Note I'm working on a Ubuntu 12.10 system with PHP 5.5.9 and Apache Webserver 2.4.6

    0 讨论(0)
  • 2020-11-30 11:31

    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!

    0 讨论(0)
  • 2020-11-30 11:33

    Edit php.ini and add:

    extension=php_pdo_mysql.dll 
    

    Then restart your web server

    0 讨论(0)
  • 2020-11-30 11:34

    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.

    0 讨论(0)
  • 2020-11-30 11:34

    Just to help Ubuntu users out: I had the same error in my ubuntu 13.10 machine with the newest xampp downlaoded directly from apachefriends. Tried most of the stuff in every post I could find about this error, but not the mac-specific stuff. In the end, the fix happened to be the same as the elected answer here:

    Find the socket that mysqld creates for programs to connect to:

    user@host /opt$ find . -name mysql.sock
    /opt/lampp/var/mysql/mysql.sock
    

    add it to your cakePHP database configuration file (cakePHP)/app/Config/database.php

    'unix_socket' => '/opt/lampp/var/mysql/mysql.sock'
    

    To me, this finally resulted in my cake commands being able to be executed without the "Error: Database connection "Mysql" is missing, or could not be created.".

    0 讨论(0)
提交回复
热议问题