zen of coding

“Error: Database connection “Mysql” is missing, or could not be created”. CakePHP 2.0 — cake bake trouble

CakePHP 2.0

Nothing like coming back from a hiatus with a WTF? post.
My favorite “cake bake” started failing with the message in the subject; as well it seems that I am not the only one who had suffered from the problem… (just give it a quick check on google).

After a little research here’s a summary of issues and steps to check:

The problem is caused the the fact that the PDO drivers are not available when you run php5 in cli mode (i.e. “cake bake”).

  1. First thing you’d want to check is which php.ini file is being used by your php (in cli mode!).
  2. In your terminal (or command prompt), run: php –ini. This will show the location of the currently used files. In many cases it is possible that your system php is not the same as your web server php, which you might have installed with something like XAMPP. If this is the case you need to change your path to use the correct install of php, which should have the necessary drivers available.
  3. Next step would be to check your php.ini (which is sometimes broken into a few config files). Check the PDO settings to make sure you have the correct extension enabled (might be as simple as un-commenting a line). For example, I am using MySQL therefore I needed to have MySQL PDO extension available (when running in cli!). It was working perfectly well “on the web”.
  4. Turns out I needed to run: sudo apt-get install php5-mysql

That was unexpected a little since CakePHP had no connection problems to MySQL, but there you go. This should cover all possible cases.
If you find other solutions not outlined here, please share.

  • David

    Thanks for this, fixed my problem.

    I am using a WAMP called Uniserver. After following the trail of other people with this same error message from all over the net I found the problem lies with the MySQL PDO. I checked my php.ini and “extension=php_pdo_mysql.dll” was enabled so I was going crazy trying to find another reason for the problem. Finally found that my PHP was using another config file called php-cli.ini in the same folder. Had to copy the line “extension=php_pdo_mysql.dll” into the php-cli.ini file.

    Solution: Use the console command ‘php –ini’ as above. Find which config file is being used, make sure to note the name of the actual file name not just the path, it might not be php.ini.

    Then ensure “extension=php_pdo_mysql.dll” is uncommented/present in the file.

    Thanks again!

    • DafT

      Thanks greatly for your response! It helped me solve the same issue.

  • Been searching for a minute here, everything I saw about cakephp was about baking, and turns out I needed to install php-mysql as well…


  • Tutakahil

    Nice article, wish you could put steps needed to solve the eventual problems. Like should we make ubuntu point to xampp’s php.ini rather than the systems.

  • David

    I have googled for 2 hours, set up everything recommended here, on stackoverflow and wherever I found any piece of information. Finally I found out that my DB I referenced in config/database.php didn’t exist.
    So be aware to check the basics too, because this kind of mistakes result in this same error message.

  • solycon

    Please check the services is running, the user name and password, and database name, the cake is great, but the error messages in the connection are poor.

  • Mick

    @250d8819252978ab6a217390a557abd1:disqus spot on! At home I’m using the Uniform Server @ http://www.uniformserver.com/ and it uses a seperate PHP INI file for CLI stuff, which of course is what I need when I’m baking :) In the office I use XAMPP so there is no distinction.

  • ThinkMn

    Thanks for the info. Going from an earlier version to the latest version caused this problem. I figured it was something stupid.
    I am using wampserver (test environment) and just enabled. php_pdo_mysql under extensions and everything works.

  • Rahul

    if you guys are using xampp on ubuntu, Tis is a solid solution

    1. Go to location /home/rahul (In my case)

    2. ctl+ H (to show all hidden files)

    3. search for .profile file

    4. add a line at the end ” PATH=/opt/lampp/bin:$PATH ”

    5. Restart you sysyem
    6.Bingo!!!!!! ends of you all problems

  • FaustoW

    try adding the path to your mysql.sock in your database.php file

  • r0bertisnki

    I still having the problem, and php.ini modules seems working fine.

    Configuration File (php.ini) Path: /etc/php5/cli
    Loaded Configuration File: /home/ubuntu/workspace/php.ini
    Scan for additional .ini files in: /etc/php5/cli/conf.d
    Additional .ini files parsed: /etc/php5/cli/conf.d/05-opcache.ini,

%d bloggers like this: