Answers.Body: <p>finally worked it out! when connecting through <code>localhost</code> PDO does a socket-based connection to mysql, not tcp. under MAMP the socket file is "non-standard", and so i have to set it explicitly. when running a console command via yiic.php, <code>CRAFT_ENVIRONMENT</code> is set to <code>console</code>, and so i add the following to the end of <code>craft/config/db.php</code>:</p>
  
  <pre><code>'console' =&gt; [
      'unixSocket' =&gt; '/Applications/MAMP/tmp/mysql/mysql.sock',
  ],
  </code></pre>
  
  <p>and all is well.</p>
  
  <h3>UPDATE: Better Solution</h3>
  
  <p>the above is not optimal as obviously one can run a plugin from the console on a live or staging server, as well as a dev machine! so i came up with a better approach: add support for a <code>--mamp</code> cmdline parameter. so my db.php became:</p>
  
  <pre><code>$db_config = [
  
      '*' =&gt; [
          'server' =&gt; 'localhost',
          'user' =&gt; '...',
          'password' =&gt; '...',
          'database' =&gt; '...',
          'tablePrefix' =&gt; 'craft',
      ],
  
  ];
  
  // watch for MAMP (need to specify socket file explicitly)
  if (php_sapi_name() == "cli") {
      $idx = 0;
      foreach($_SERVER['argv'] as $key =&gt; $arg) {
          if (strcasecmp($arg, '--mamp') === 0) {
              $db_config['*']['unixSocket'] = '/Applications/MAMP/tmp/mysql/mysql.sock';
              array_splice($_SERVER['argv'], $idx, 1);
              break;
          }
          $idx++;
      }
  }
  
  
  return $db_config;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T18:10:01.520Z
Answers.Text: Very helpful. Thanks. For my own future reference as well as others, my full command line was then `./yiic migrate create MyDataBaseUpdate MyPlugin --mamp`
Answers.UserDisplayName: John Morton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-16T10:45:37.790Z
Answers.Text: Feel free to mark your own answer as correct! Certainly worked for me :)
Answers.UserDisplayName: Josh Angell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-11T17:52:03.613Z
Answers.Text: Any luck with this in Craft 3?
Answers.UserDisplayName: Stian Karlsen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-26T14:15:40.557Z
Answers.LastActivityDate: 2015-11-28T01:10:34.283Z
Answers.LastEditDate: 2015-11-28T01:10:34.283Z
Answers.UserDisplayName: bhu Boue vidya
Body: <p>i know this might be a bit out of bounds for this stackexchange site, but i am going a bit batty and any help would be amazing</p>
  
  <p>i am trying to get a console plugin up and running. i started with just the shell of one. got all the basics in place. then when i run <code>craft/app/etc/console/yiic.php</code> (with no params) to get a list of available commands, i get db connection errors.</p>
  
  <p>things to note:</p>
  
  <ul>
  <li>i can run <code>yiic.php</code> on my staging server (a centos LAMP cloud server instance at Rackspace) and it's fine, it just has problems locally</li>
  <li>i am using MAMP Pro locally</li>
  <li>i can load the site fine through my browser, so credentials in <code>config\db.php</code> are AOK</li>
  <li>i can fire up mysql from the cmdline using the same db credentials, and it's fine</li>
  </ul>
  
  <p>any help would be so appreciated!</p>
  
  <p>the dumped errors i get are as follows:</p>
  
  <pre><code>CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (829)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (842)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (829)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (842)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (829)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (842)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  exception 'CException' with message 'Craft\ConsoleApp and its behaviors do not have a method or closure named "getTranslatedBrowserLanguage".' in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/base/CComponent.php:266
  Stack trace:
  #0 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(910): CComponent-&gt;__call('getTranslatedBr...', Array)
  #1 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(910): Craft\ConsoleApp-&gt;getTranslatedBrowserLanguage()
  #2 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(800): Craft\AppBehavior-&gt;_getFallbackLanguage()
  #3 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(570): Craft\AppBehavior-&gt;getTargetLanguage(false)
  #4 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(103): Craft\AppBehavior-&gt;getLanguage()
  #5 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/i18n/CMessageSource.php(83): Craft\ConsoleApp-&gt;getLanguage()
  #6 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/YiiBase.php(590): CMessageSource-&gt;translate('craft', 'Craft can\xE2\x80\x99t c...', NULL)
  #7 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/Craft.php(382): YiiBase::t('craft', 'Craft can\xE2\x80\x99t c...', Array, NULL, NULL)
  #8 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(843): Craft\Craft::t('Craft can\xE2\x80\x99t c...')
  #9 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(203): Craft\AppBehavior-&gt;createDbConnection()
  #10 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(80): Craft\ConsoleApp-&gt;getComponent('db')
  #11 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(487): Craft\AppBehavior-&gt;isInstalled()
  #12 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(187): Craft\AppBehavior-&gt;getInfo('edition')
  #13 [internal function]: Craft\AppBehavior-&gt;getEdition()
  #14 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/base/CComponent.php(261): call_user_func_array(Array, Array)
  #15 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(307): CComponent-&gt;__call('getEdition', Array)
  #16 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(307): Craft\ConsoleApp-&gt;getEdition()
  #17 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(74): Craft\ConsoleApp-&gt;_setEditionComponents()
  #18 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/base/CApplication.php(169): Craft\ConsoleApp-&gt;init()
  #19 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/YiiBase.php(121): CApplication-&gt;__construct('/Users/bhu/drop...')
  #20 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/yiic.php(78): YiiBase::createApplication('Craft\\ConsoleAp...', '/Users/bhu/drop...')
  #21 {main}
  </code></pre>
  
Tags: <plugin-development>
Title: Error Connecting To (MAMP Pro) Database in Console Command
ThreadText: # Error Connecting To (MAMP Pro) Database in Console Command
  
  (Asked by: username_0 on 2015-11-26)
  
  i know this might be a bit out of bounds for this stackexchange site, but i am going a bit batty and any help would be amazing
  
  i am trying to get a console plugin up and running. i started with just the shell of one. got all the basics in place. then when i run `craft/app/etc/console/yiic.php` (with no params) to get a list of available commands, i get db connection errors.
  
  things to note:
  
  * i can run `yiic.php` on my staging server (a centos LAMP cloud server instance at Rackspace) and it's fine, it just has problems locally
  * i am using MAMP Pro locally
  * i can load the site fine through my browser, so credentials in `config\db.php` are AOK
  * i can fire up mysql from the cmdline using the same db credentials, and it's fine
  
  any help would be so appreciated!
  
  the dumped errors i get are as follows:
  
  ```
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (829)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (842)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (829)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (842)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (829)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (842)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php (203)
  in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php (80)
  exception 'CException' with message 'Craft\ConsoleApp and its behaviors do not have a method or closure named "getTranslatedBrowserLanguage".' in /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/base/CComponent.php:266
  Stack trace:
  #0 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(910): CComponent->__call('getTranslatedBr...', Array)
  #1 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(910): Craft\ConsoleApp->getTranslatedBrowserLanguage()
  #2 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(800): Craft\AppBehavior->_getFallbackLanguage()
  #3 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(570): Craft\AppBehavior->getTargetLanguage(false)
  #4 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(103): Craft\AppBehavior->getLanguage()
  #5 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/i18n/CMessageSource.php(83): Craft\ConsoleApp->getLanguage()
  #6 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/YiiBase.php(590): CMessageSource->translate('craft', 'Craft can\xE2\x80\x99t c...', NULL)
  #7 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/Craft.php(382): YiiBase::t('craft', 'Craft can\xE2\x80\x99t c...', Array, NULL, NULL)
  #8 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(843): Craft\Craft::t('Craft can\xE2\x80\x99t c...')
  #9 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(203): Craft\AppBehavior->createDbConnection()
  #10 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(80): Craft\ConsoleApp->getComponent('db')
  #11 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(487): Craft\AppBehavior->isInstalled()
  #12 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/behaviors/AppBehavior.php(187): Craft\AppBehavior->getInfo('edition')
  #13 [internal function]: Craft\AppBehavior->getEdition()
  #14 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/base/CComponent.php(261): call_user_func_array(Array, Array)
  #15 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(307): CComponent->__call('getEdition', Array)
  #16 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(307): Craft\ConsoleApp->getEdition()
  #17 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/ConsoleApp.php(74): Craft\ConsoleApp->_setEditionComponents()
  #18 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/base/CApplication.php(169): Craft\ConsoleApp->init()
  #19 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/framework/YiiBase.php(121): CApplication->__construct('/Users/bhu/drop...')
  #20 /Users/bhu/dropbox-bhu/Dropbox/devel/binarybhu/websites/blackstarcoffee/blackstarcoffee.dev/craft/app/etc/console/yiic.php(78): YiiBase::createApplication('Craft\\ConsoleAp...', '/Users/bhu/drop...')
  #21 {main}
  
  ```
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-11-26. Score: 4 | Accepted answer
  
  finally worked it out! when connecting through `localhost` PDO does a socket-based connection to mysql, not tcp. under MAMP the socket file is "non-standard", and so i have to set it explicitly. when running a console command via yiic.php, `CRAFT_ENVIRONMENT` is set to `console`, and so i add the following to the end of `craft/config/db.php`:
  
  ```
  'console' => [
      'unixSocket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
  ],
  
  ```
  
  and all is well.
  
  ### UPDATE: Better Solution
  
  the above is not optimal as obviously one can run a plugin from the console on a live or staging server, as well as a dev machine! so i came up with a better approach: add support for a `--mamp` cmdline parameter. so my db.php became:
  
  ```
  $db_config = [
  
      '*' => [
          'server' => 'localhost',
          'user' => '...',
          'password' => '...',
          'database' => '...',
          'tablePrefix' => 'craft',
      ],
  
  ];
  
  // watch for MAMP (need to specify socket file explicitly)
  if (php_sapi_name() == "cli") {
      $idx = 0;
      foreach($_SERVER['argv'] as $key => $arg) {
          if (strcasecmp($arg, '--mamp') === 0) {
              $db_config['*']['unixSocket'] = '/Applications/MAMP/tmp/mysql/mysql.sock';
              array_splice($_SERVER['argv'], $idx, 1);
              break;
          }
          $idx++;
      }
  }
  
  return $db_config;
  
  ```
  
  > **Comments:**
  > **username_1**: Very helpful. Thanks. For my own future reference as well as others, my full command line was then `./yiic migrate create MyDataBaseUpdate MyPlugin --mamp`  
  > **username_2**: Feel free to mark your own answer as correct! Certainly worked for me :)  
  > **username_3**: Any luck with this in Craft 3?  
  
  ---
  
  