Drush can't connect to MySQL server on localhost using WinNMP on Windows

First time I setup and test Drush on my local machine using WinNMP on Windows executing a cache clear on a local Drupal site under Git BASH or cygwin:

  
drush @webfoobar cache-rebuild
  

... I get this error:

  
No Drupal site found, only 'drush' cache was cleared
  

I excuted the following drush command to investigate the cause of the error:

  
drush @webfoobar -d st
  

... got the following output message:

  
sql-query: SELECT 1; [0.47 sec, 6.3 MB]                                                                                                                                                                    [notice]
Executing: mysql --defaults-extra-file=/tmp/dru65F4.tmp" --database=webfoobardb --host=localhost --silent  

WinNMP uses bash script to call the actual MySQL client bin file. Upon checking this script, I found that it needs to add winpty because the script is excuted under Git BASH or cygwin. Correcting the script, we have now the following codes:

  
#!/usr/bin/env sh
dir=$(d=${0%[/\\]*}; cd "$d"; cd ".."; pwd)
app=$dir/bin/mariadb64/bin/mysql
if [[ $@ =~ '--defaults-extra-file' ]];
then
  "winpty" "$app" "$@"
else
  ini=$dir/conf/mysql.ini
  "winpty" "$app" "--defaults-file=$ini" "$@"
fi
  

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.