I've been trying to follow the docs for creating a plugin migration (https://craftcms.com/docs/plugins/migrations) but any attempts to run yiic seem to die with:

CDbConnection failed to open the DB connection.

My Google-fu has not come up with any relevant answers. This is with Craft setup in a Vagrant box, if that makes a difference.


If you're using 'localhost' for the 'server' in craft/config/db.php, try '' and visa-versa.

For some reason, some environments are picky about that when connecting to MySQL from the CLI.

  • 1
    That was it (sort of). I had multiple environments in the config file, but yiic needed something in the default (*) array.
    – jjmartucci
    Feb 12 '15 at 2:35
  • Ahh, yeah. There is no domain to match, so it needs something for the default. Nice catch.
    – Brad Bell
    Feb 12 '15 at 3:02
  • I still have this issue, any other ideas to try? Mar 5 '15 at 11:18
  • @LukeHolder I'm out of ideas. Those are usually the 2 reasons I've seen it happen.
    – Brad Bell
    Mar 5 '15 at 16:18
  • 1
    It seems you need every config line of your local environment in the default '*' => array(. So don't forget user, password and database...
    – luwes
    Jun 15 '16 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.