Answers.Body: <p>If you're using 'localhost' for the 'server' in <code>craft/config/db.php</code>, try '127.0.0.1' and visa-versa.</p>
  
  <p>For some reason, some environments are picky about that when connecting to MySQL from the CLI.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-05T11:18:01.740Z
Answers.Text: I still have this issue, any other ideas to try?
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-05T16:18:42.420Z
Answers.Text: @LukeHolder I'm out of ideas. Those are usually the 2 reasons I've seen it happen.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-06T03:37:26.843Z
Answers.Text: had to drop using yiic... manual migration creation for me!
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-17T03:49:01.233Z
Answers.Text: I tried setting the unixSocket though, didn't seem to work ([link to code](https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/config/defaults/db.php#L53-L58))
Answers.UserDisplayName: Natetronn
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-12T02:35:55.503Z
Answers.Text: That was it (sort of). I had multiple environments in the config file, but yiic needed something in the default (*) array.
Answers.UserDisplayName: jjmartucci
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-12T03:02:52.747Z
Answers.Text: Ahh, yeah.  There is no domain to match, so it needs something for the default.  Nice catch.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-15T08:36:28.343Z
Answers.Text: It seems you need every config line of your local environment in the default `'*' => array(`. So don't forget `user`, `password` and `database`...
Answers.UserDisplayName: luwes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-09T09:25:28.887Z
Answers.Text: unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock did the trick for me. Check https://stackoverflow.com/questions/41852050/yii-console-command-cant-connect-to-database?rq=1
Answers.UserDisplayName: Jan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-12T00:01:58.000Z
Answers.LastActivityDate: 2015-02-12T00:01:58.000Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've been trying to follow the docs for creating a plugin migration (<a href="https://craftcms.com/docs/plugins/migrations" rel="nofollow noreferrer">https://craftcms.com/docs/plugins/migrations</a>) but any attempts to run yiic seem to die with:</p>
  
  <pre><code>CDbConnection failed to open the DB connection.
  </code></pre>
  
  <p>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. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-17T02:59:18.180Z
Comments.Text: I've run into this as well when following [this tutorial](http://spin.atomicobject.com/2015/06/16/craft-console-plugin/)
Comments.UserDisplayName: Natetronn
Tags: <plugin-development><migration>
Title: Using Yiic for plugin migration
ThreadText: # Using Yiic for plugin migration
  
  (Asked by: username_0 on 2015-02-11)
  
  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.
  
  **Tags:** plugin-development, migration
  
  > **Comments:**
  > **username_1**: I've run into this as well when following [this tutorial](http://spin.atomicobject.com/2015/06/16/craft-console-plugin/)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-02-12. Score: 2
  
  If you're using 'localhost' for the 'server' in `craft/config/db.php`, try '127.0.0.1' and visa-versa.
  
  For some reason, some environments are picky about that when connecting to MySQL from the CLI.
  
  > **Comments:**
  > **username_0**: That was it (sort of). I had multiple environments in the config file, but yiic needed something in the default (*) array.  
  > **username_2**: Ahh, yeah.  There is no domain to match, so it needs something for the default.  Nice catch.  
  > **username_3**: I still have this issue, any other ideas to try?  
  > **username_2**: @username_3 I'm out of ideas. Those are usually the 2 reasons I've seen it happen.  
  > **username_3**: had to drop using yiic... manual migration creation for me!  
  > **username_1**: I tried setting the unixSocket though, didn't seem to work ([link to code](https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/config/defaults/db.php#L53-L58))  
  > **username_4**: It seems you need every config line of your local environment in the default `'*' => array(`. So don't forget `user`, `password` and `database`...  
  > **username_5**: unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock did the trick for me. Check https://stackoverflow.com/questions/41852050/yii-console-command-cant-connect-to-database?rq=1  
  
  ---
  
  