Drush无法连接到MAMP上的MySQL?

时间:2013-10-10 16:12:25

标签: macos drupal mamp drush

我试图第一次设置Drush。我正在使用Mamp和Mountain Lion。当我在终端输入'drush'时,我得到一个命令列表,所以它似乎安装好了。

我已更改MAMP中的默认网络目录文件夹。我在web目录中的文件夹中有许多Drupal站点。因此,一个网站的网址为http://localhost:8888/omega/omegav3/,另一个网站的网址为http://localhost:8888/omega/omegav4/

通过导航到终端中的站点文件夹,我可以运行Drush命令,但是我收到错误。当我下载视图时,它会将模块正确下载到我的sites / all / modules文件夹,但它会给我一些错误。当我尝试启用模块时,它会给我更多错误,并且不会启用模块。

unknown:omegav3 MYUSERNAME$ cd /Users/MYUSERNAME/Dropbox/sites/omega/omegav3 
unknown:omegav3 MYUSERNAME$ drush dl views
PDO::__construct(): [2002] No such file or directory (trying to connect via           [warning]
unix:///var/mysql/mysql.sock) environment.inc:523
Project views (7.x-3.7) downloaded to sites/all/modules/views.                        [success]
Project views contains 2 modules: views, views_ui.
unknown:omegav3 MYUSERNAME$ 
unknown:omegav3 MYUSERNAME$ drush en views
PDO::__construct(): [2002] No such file or directory (trying to connect via           [warning]
unix:///var/mysql/mysql.sock) environment.inc:523
Command pm-enable needs a higher bootstrap level to run - you will need to invoke     [error]
drush from a more functional Drupal environment to run this command.
The drush command 'en views' could not be executed.                                   [error]
Drush was not able to start (bootstrap) the Drupal database.                          [error]
Hint: This may occur when Drush is trying to:
 * bootstrap a site that has not been installed or does not have a configured
database. In this case you can select another site with a working database setup by
specifying the URI to use with the --uri parameter on the command line. See `drush
topic docs-aliases` for details.
 * connect the database through a socket. The socket file may be wrong or the php-cli
may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for
details.

Drush was attempting to connect to: 
 Drupal version         :  7.23                                             
 Site URI               :  http://default                                   
 Database driver        :  mysql                                            
 Database username      :  root                                             
 Database name          :  omegav3                                          
 Default theme          :  garland                                          
 Administration theme   :  garland                                          
 PHP executable         :  /usr/bin/php                                     
 PHP configuration      :                                                   
 PHP OS                 :  Darwin                                           
 Drush version          :  6.1.0                                            
 Drush configuration    :                                                   
 Drush alias files      :                                                   
 Drupal root            :  /Users/MYUSERNAME/Dropbox/sites/omega/omegav3 
 Site path              :  sites/default                                    
 File directory path    :  sites/default/files                              


unknown:omegav3 MYUSERNAME$ 

这似乎是Drush和MySQL的问题,但我不知道如何解决这个问题。我是命令行的新手,我从来没有安装像Drush之类的东西,所以我真的很挣扎。

5 个答案:

答案 0 :(得分:4)

让我们开始说我根本不熟悉Drush。但是从MAMP的角度看这个,我想我知道这里发生了什么。

这条线 PDO::__construct(): [2002] No such file or directory (trying to connect via [warning] unix:///var/mysql/mysql.sock) environment.inc:523说明了一切。

默认情况下,MAMP正在/Applications/MAMP/tmp/mysql/mysql.sock创建MySQL套接字,如MAMP启动页面所述。但是,Drush希望套接字位于var/mysql/mysql.sock

有两种方法可以解决这个问题。

  1. 停止所有MAMP服务器。编辑文件/Applications/MAMP/bin/startMysql.sh, 将--socket=/Applications/MAMP/tmp/mysql/mysql.sock更改为--socket=/var/mysql/mysql.sock。并且不要忘记编辑stopMysql.sh。这告诉MAMP在下次启动Mysql服务器时将套接字存储在别处。

  2. 创建一个从/var/mysql/mysql.sock/Applications/MAMP/tmp/mysql/mysql.sock的符号链接,请参阅this帖子,了解有关符号链接的更多信息。由于套接字文件是动态创建的,因此需要运行MAMP才能执行此操作。

  3. 祝你好运!

答案 1 :(得分:3)

我有同样的问题 - 为我解决的是改变了settings.php中的数据库主机来自" localhost"到" 127.0.0.1"。

答案 2 :(得分:3)

对我来说,mysql bin并不存在。

sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql

为我修好了。

答案 3 :(得分:1)

作为回答#1的替代方案,我建议您更改命令行MySQL以使用MAMP - 这可以确保当您从命令行使用mysql时,它也能正常工作。编辑〜/ .bash_profile并添加以下行:

alias mysql='/Applications/MAMP/Library/bin/mysql'

答案 4 :(得分:1)

这对我有用

sudo mkdir / var / mysql sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock