2015-06-19 124 views
7

我有問題運行烘烤命令。我認爲這是關係到MySQL,但我沒有找到任何解決方案這個錯誤在Stackoverflow。 這是我app.phpSQLSTATE HY000 2002運行烘烤命令時

'Datasources' => [ 
     'default' => [ 
      'className' => 'Cake\Database\Connection', 
      'driver' => 'Cake\Database\Driver\Mysql', 
      'persistent' => false, 
      'host' => 'localhost', 

      //'port' => 'nonstandard_port_number', 
      'username' => 'root', 
      'password' => 'root', 
      'database' => 'laboiterose', 
      'encoding' => 'utf8', 
      'timezone' => 'UTC', 
      'cacheMetadata' => true, 

請幫幫忙,錯誤我得到的是:

Exception: SQLSTATE[HY000] [2002] No such file or directory in [/Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php, line 48] 
2015-06-19 14:35:48 Error: [PDOException] SQLSTATE[HY000] [2002] No such file or directory 
Stack Trace: 
0 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php(48): PDO->__construct('mysql:host=loca...', 'root', 'root', Array) 
1 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php(89): Cake\Database\Driver\Mysql->_connect('mysql:host=loca...', Array) 
2 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Schema/BaseSchema.php(46): Cake\Database\Driver\Mysql->connect() 
3 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Dialect/MysqlDialectTrait.php(62): Cake\Database\Schema\BaseSchema->__construct(Object(Cake\Database\Driver\Mysql)) 
4 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Schema/Collection.php(52): Cake\Database\Driver\Mysql->schemaDialect() 
5 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Schema/CachedCollection.php(44): Cake\Database\Schema\Collection->__construct(Object(Cake\Database\Connection)) 
6 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Database/Connection.php(319): Cake\Database\Schema\CachedCollection->__construct(Object(Cake\Database\Connection), true) 
7 /Applications/MAMP/htdocs/my_db/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(806): Cake\Database\Connection->schemaCollection() 
8 /Applications/MAMP/htdocs/my_db/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(782): Bake\Shell\Task\ModelTask->_getAllTables() 
9 /Applications/MAMP/htdocs/my_db/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(186): Bake\Shell\Task\ModelTask->listAll() 
10 /Applications/MAMP/htdocs/my_db/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(109): Bake\Shell\Task\ModelTask->getAssociations(Object(Cake\ORM\Table)) 
11 /Applications/MAMP/htdocs/my_db/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(95): Bake\Shell\Task\ModelTask->bake('Users') 
12 /Applications/MAMP/htdocs/my_db/vendor/cakephp/bake/src/Shell/BakeShell.php(241): Bake\Shell\Task\ModelTask->main('Users') 
13 [internal function]: Bake\Shell\BakeShell->all('users') 
14 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Console/Shell.php(380): call_user_func_array(Array, Array) 
15 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(204): Cake\Console\Shell->runCommand(Array, true) 
16 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(175): Cake\Console\ShellDispatcher->_dispatch() 
17 /Applications/MAMP/htdocs/my_db/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(126): Cake\Console\ShellDispatcher->dispatch() 
18 /Applications/MAMP/htdocs/my_db/bin/cake.php(33): Cake\Console\ShellDispatcher::run(Array) 
19 {main} 
+0

與Zend教程[開始的可能重複 - Zend的\ _db \ _Adapter拋出異常:「SQLSTATE \ [HY000 \] \ [2002 \] No such file or directory「](http://stackoverflow.com/questions/2412009/starting-with-zend-tutorial-zend-db-adapter-throws-exception-sqlstatehy000) – ndm

回答

8

問題解決了! 我要補充的唯一事情是此行中的.bash_profile,使其工作:

export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH 
+1

你能解釋爲什麼這使它工作,因爲它爲我工作。(也有人應該在重啓終端之後) – efwjames

+1

@liquified它改變了由MAC OS X預裝的默認PHP安裝路徑到導致MAMP PHP安裝的路徑。 – hardcodepunk

-2

可以測試

'default' => [ 
     'className' => 'Cake\Database\Connection', 

     'driver' => 'Cake\Database\Driver\Mysql', 

     'persistent' => false, 

     'host' => 'localhost', 

     'username' => 'root', 

     'password' => '', 

     'database' => 'laboiterose', 

     'encoding' => 'utf8', 

     'timezone' => 'UTC', 

     'cacheMetadata' => true, 

     'quoteIdentifiers' => false, 

    ], 
5

首先,讓我們看看我們正在運行什麼版本的PHP(要了解它的默認版本)。

爲了做到這一點,在終端內,消防以下命令:

which php 

這應該輸出的路徑,默認的PHP安裝的自帶由Mac OS X預裝,默認情況下它必須(假設你「VE不發生變化的話):

/usr/bin/php 

現在,我們只需要過來的安裝與MAMP的PHP,這是位於/Applications/MAMP/bin/php/php7.0.0/交換這bin(MAMP 3.5)

爲此,我們需要編輯.bash_profile並將PHP的MAMP版本添加到PATH變量中。 按照這些簡單的步驟:

在終端內,運行vim ~/.bash_profile

類型i,然後粘貼在該文件的頂部如下:

export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH 

按Esc鍵,:wq類型,然後按Enter

在終端,運行source ~/.bash_profile

在終端中,再次輸入which php並查找更新的字符串。如果一切順利,它應該輸出新的路徑到MAMP PHP安裝。

如果不輸出正確的路徑,請嘗試關閉終端窗口(完全退出)並再次打開,它應該應用更改(簡稱重啓)。

3

我覺得這是最好的方法:

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', 

在你的數據庫的配置添加此

+0

對於xampp,字符串將類似於''unix_socket'=>'/ opt/lampp/var/mysql/mysql.sock',' –

相關問題