On several shared-hosting servers I have used for Drupal, a jailshell is provided for ssh access. Drush may not work on a such system if the jailshell does not provide access to /var/lib/mysql/mysql.sock.
Note (2015-11-06): As this issue is being referenced in Drush, it also serves as a guide on fixing the bootstrapping error in different, newer enviroments (AMP stacks on OSX, Linux + VMs).
Please refer to solutions in comments like #23 and #43 and #44 for this case.
You can see if drush is going to work just by trying mysql from the command line. If you get an error like below, it probably will not:
# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)The usual workaround suggested is to change the 'host' setting in your settings.php. Before the change, it looks something like this (in D7: D6 is analogous but uses $db_url = 'mysql://username:password@localhost/databasename';):
$databases = array (
[...]
'database' => 'yourdatabase',
'username' => 'yourusername',
'password' => 'yourpassword',
'host' => 'localhost',
[...]
MySQL treats 'localhost' specially, and uses the Unix socket instead of a network socket. If you change the 'host' to 127.0.0.1:
'host' => '127.0.0.1',
then MySQL always uses a network socket, and drush will work. However, this is not the best idea, because it's more efficient to use the Unix socket (I've seen benchmarks of 6-10% faster).
I tried using a drush alias to change the $databases setting, but not successfully (cf. #1335626: alias db-url is ignored). So I am now using this simple bit of code in settings.php which works for m. Change the 'host' line to:
'host' => php_sapi_name() == 'cli' ? '127.0.0.1' : 'localhost',
I have not seen suggested elsewhere. It is a simplified version of how drush checks for being run from the command line:
function drush_verify_cli() {
return (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER[
'argc'] > 0));
}You may need the more complicated check for some hosts.
If someone has an alternate suggestion for getting drush to use 127.0.0.1 without messing with settings.php, I would be interested in hearing it. I have filed this as a support request, but it could turn into a documentation task.
Comments
Comment #1
dhalbert commentedSomehow the end of the OP got truncated. To finish:
This is similar to what drush uses to check for being run from the command line:
For some hosts, the extra check may be necessary.
If someone has a better way of doing this with drush, I'd be interested in hearing it. Otherwise I'd suggest that some hint like this going into the drush documentation somewhere (and this issue would turn into a documentation task).
Comment #2
moshe weitzman commentedPersonally, I just use 127.0.0.1 and be done with it. But drush5 honors Drupal 7's unix socket support - #437642: support for different MYSQL socket
Comment #4
dylanb commentedApologies if I'm just supplying subtitles for the hard of understanding but in case you need to edit your drupal 6 settings.php file to use the localhost socket for regular website activity and 127.0.0.1 for drush then this works for me...
Comment #5
ceeweb commentedSorry to "reopen" this case, but I have the same problem except I am using Postgresql and this solution did not work for me....
My drupal installation is installed at: C:\SiteData\WebDev\gitproject (this is my DrupalRoot)
I successfully ran "drush status" in "[DrupalRoot]\sites\site1.example.com..
But when I try to enable a module using "drush en ccl" and I get ...
======================================
My settings.php file looks like this:
==============================
I have used both the "Drush Command Prompt" and "MINGW32" git command line tool and both work for "drush status" or "drush dl " but not for "drush en "
One last comment. looking at the settings.php file permissions in MINGW32 they show the unix permissions of -rw-r--r--.. Tried changing this in using chmod but doesn't work on a windows file (not even sure that makes a difference).
Any help is much appreciated!
Comment #6
helmo commentedDrush has moved to Github.
If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).
Please ask support questions on Drupal Answers.
Comment #7
ceeweb commentedThanks helmo I opened a drush issues ticket on github at https://github.com/drush-ops/drush/issues/492 and on Drupal Answers at http://drupal.stackexchange.com/questions/105274/drush-enable-module-not.... This can be closed.
Comment #8
ceeweb commentedComment #9
matt.c commentedHello,
I am having difficulty using Drush on my Webdisk server, can somebody please assist me.
1) Drush is properly installed on my computer, when I type drush version I get: Drush Version : 7.0-dev
2) I can install modules, when I cd /sites/all/modules and type drush dl disqus for instance
3) I properly installed the theme omega in my /sites/all/themes
4) The error is occurring when I try to run the drush omega-wizard to create a new Omega sub theme
I am getting the following error message
Can somebody please help me with why Drush is working for some commands and not for others? What do I need to change?
Thanks,
- Matt
Comment #10
helmo commented@matt.c: This issue is already closes ... See https://drupal.org/comment/8533111#comment-8533111
Comment #11
jaypanThis is so horrible for the Drupal community. It really disappoints me that the maintainers of Drush, such an integral part of Drupal, would choose to be so anti-community. Someone should branch Drush and keep it on Drupal.
Comment #12
raulmuroc commentedAgree with Jaypan.
Comment #13
protools commented1) try run mysql from command line:
$ mysql
If not found error, create symbol link to bash:
$ sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql
try drush en
2) If not working and in setting.php you using unix socket like: 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
try create symbol link to unix socket:
$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/lib/mysql/mysql.sock
ore
$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
work for me on OS X yosemite + MAMP 3
Comment #14
Anonymous (not verified) commentedDamn, setting up Drush is soooooo hard
For such a highly recommended tool it is so elusive and reserved only for the technically gifted.
It's taken me a week to get to the stage where I can install a module
Now, I have to reserve another week to work out how to enable it
It's all character building I suppose :)
protools offered me a glimmer of hope, but his option 2) has me hit a wall as I do not have
"/Applications/MAMP/tmp/mysql/mysql.sock "
So now have to learn about that...
blimey, is it worth it? YES, I hear you cry
Comment #15
jazzper commentedI am not able to get drush to work properly:
1) I can download modules & themes through drush but I cannot enable them (more details below).
2) Also I cannot use the omega commands even though they are listed (more details below).
= I installed Composer & Drush as per http://docs.drush.org/en/master/install/
= Drush is properly installed on my computer, when I type drush version I get: Drush Version : 7.0-dev
My system setup:
Linux mint 17 kde
Xampp 1.8.3-4
I guess my problems are (partly?) caused because Drush was not able to start (bootstrap) the Drupal database. So I run mysql from command line:
user@mylaptop:/opt/lampp/htdocs/drush/sites/all/modules > mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
In my system mysqld.sock is in a different location, namely /opt/lampp/var/mysql/mysql.sock. So I created a symbolic link in /var/run/mysqld/ but this has no effect. Still have the same problems. Maybe caused by permissions?
I have spend a few days of and on (had to stop out of frustration) and I cannot get drush to work. I know this issue is closed and I will post my problems on git but maybe somebody here knows what goes wrong. Any help would be much appreciated.
Details of my problems:
1) I can download modules & themes through drush but I cannot enable them:
user@mylaptop:/opt/lampp/htdocs/drush/sites/all/modules > drush en disqus
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 disqus' 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.34
Site URI : http://default
Database driver : mysql
Database hostname : localhost
Database port :
Database username : root
Database name : drush
PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini
PHP OS : Linux
Drush version : 7.0-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : /opt/lampp/htdocs/drush
Site path : sites/default
When I add
'host' => php_sapi_name() == 'cli' ? '127.0.0.1' : 'localhost',
OR
'host' => '127.0.0.1',
to settings.php as per http://drupal.org/node/1428638 I get following error:
user@mylaptop:/opt/lampp/htdocs/drush/sites/all/modules > drush en disqus
PHP Fatal error: Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY' in /opt/lampp/htdocs/drush/includes/database/mysql/database.inc on line 46
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY' in
/opt/lampp/htdocs/drush/includes/database/mysql/database.inc, line 46
2) Also I cannot use the omega commands even though they are listed:
user@mylaptop:/opt/lampp/htdocs/drush/sites/all/modules > drush help --filter=omega
All commands in omega: (omega)
omega-export (oexp) Exports the theme settings of a given theme from the database to the
.info file.
omega-guard (ogrd) Runs guard for the given theme including Compass and LiveReload by
default.
omega-revert (orev) Reverts the theme settings of a given theme by deleting them from the
database.
omega-subtheme Creates a Omega subtheme.
(osub)
omega-wizard (owiz) Guides you through a wizard for generating a subtheme
Comment #16
achtonFruit fly: the Drush folks do not give support here any longer (I think), and also, this issue is for a separate (albeit) related problem. Furthermore, you seem to have multiple seperate issues (MySQL connectivity, missing extension, Omega) - it might be worth it to focus on one problem at a time.
As Moshe says in comment #2: use '127.0.0.1' for your hostname and be done with it. If you are not knowledgeable enough to fix Unix sockets (the localhost special case) in your setup, then don't waste time on it.
The error you are having when using 127.0.0.1 (Error: Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY..) is probably related to an extension you are missing. See this Google seach.
Comment #17
jazzper commentedHi achton,
Thank you for your reply. You make some good suggestions to get me back on trying to solve this problem:)
Comment #18
jazzper commentedOK I've got drush working:) For other people who might have a similar problem (hope I use the right terms):
I had to install "php5-mysql" (and dependencies) in Linux (for example through "synaptic package manager"), php5-mysql is a MYSQL module for PHP5 which contains mysql PDO support. With this I was able to enable modules and use the omega commands. Drush uses the PHP installed in Linux and not in Xammp, I had this module in Xampp but not in Linux.
You can see which php.ini file drush uses by typing "drush status" in your terminal.
You can see which php.ini file is used by your web server by navigating to admin/reports/status of your drupal site. Next click the "more information" link on Drupal's status page's PHP section. This shows the phpinfo() page. Locate the Configuration File (php.ini).
To check that the mysql PDO support is installed (part of "php5-mysql"), type the following in a terminal:
php -i|grep PDO
If support is installed you should see something like this:
PDO
PDO support => enabled
PDO drivers => mysql
PDO Driver for MySQL => enabled
Comment #19
pierrozone commentedFor anyone facing this issue with WAMP, I suggest you add mysql to your Path enviroment.
This article provides the best instructions for windows: http://drupalistasgroup.com/installing-drush-7-windows-xampp
Comment #20
bsergiu commentedWell I'm having the same issues with Command pm-disable needs a higher bootstrap level to run. For my project I'm using php5.3 and its running form my project when i run 'drush status'
Drupal version : 7.34
Site URI : http://default
Database driver : mysql
Database hostname : 127.0.0.1
Database port :
Database username : drupforma19
Database name : drupforma19
PHP executable : /Applications/AMPPS/php-5.3/bin/php
PHP configuration : /Applications/AMPPS/php-5.3/etc/php.ini
PHP OS : Darwin
Drush version : 7.0-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : /Applications/AMPPS/www/forma
Site path : sites/default
Ive changed the hostname, the mysql port is 3306 and I've already run sudo ln -s /Applications/AMPPS/mysql/tmp/mysql.sock /var/mysql/mysql.sock and that is ok but i still get the message Command pm-disable needs a higher bootstrap level to run. Any help would be appreciated.
Comment #21
bsergiu commentedWell I'm having the same issues with Command pm-disable needs a higher bootstrap level to run. For my project I'm using php5.3 and its running form my project when i run 'drush status'
Drupal version : 7.34
Site URI : http://default
Database driver : mysql
Database hostname : 127.0.0.1
Database port :
Database username : drupforma19
Database name : drupforma19
PHP executable : /Applications/AMPPS/php-5.3/bin/php
PHP configuration : /Applications/AMPPS/php-5.3/etc/php.ini
PHP OS : Darwin
Drush version : 7.0-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : /Applications/AMPPS/www/forma
Site path : sites/default
Ive changed the hostname, the mysql port is 3306 and I've already run sudo ln -s /Applications/AMPPS/mysql/tmp/mysql.sock /var/mysql/mysql.sock and that is ok but i still get the message Command pm-disable needs a higher bootstrap level to run. Any help would be appreciated.
Comment #22
Patrick Storey commentedI'm getting the same error as bsergiu although I'm using Drush 5.10.0.
Using a Mac OS, I will report back if I can figure out how to solve this.
Drupal version : 7.34
Site URI : http://default
Database driver : mysql
Database hostname : 127.0.0.1
Database username :
Database name :
Default theme : garland
Administration theme : garland
PHP configuration :
Drush version : 5.10.0
Drush configuration :
Drush alias files :
Drupal root :
Site path : sites/default
File directory path : sites/default/files
Comment #23
Patrick Storey commentedFor me it required a little more work to change my local settings.php to get the drush en to work. Using Drupal 7, MAMP Pro, PHP 5.3.29, Drush 5.10.0
In the local settings.php I had to change the following in the file for the database. Adding the unix socket and port, and then changing the host to 127.0.0.1 as shown below.
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'host' => '127.0.0.1',
'port' => '8889',
Comment #24
bsergiu commentedI've tried that as well the unix socket path is defined in my bash profile but it doesnt seem to use that sql path. The strange thing is that i managed to get it working on MAMP3, but mamp has a bug where it wont let you sign in to your durpal website after a couple of hours, so i prefer using ampps.
Comment #25
bsergiu commentedI've tried that as well the unix socket path is defined in my bash profile but it doesnt seem to use that sql path. The strange thing is that i managed to get it working on MAMP3, but mamp has a bug where it wont let you sign in to your durpal website after a couple of hours, so i prefer using ampps.
Comment #26
kevinquillen commentedSame exact issue here. I installed Drush via homebrew (6.5.0) and it works perfectly. I cannot get it to work with Drush 7 at all, installed globally over composer. I can't figure it out at all.
Comment #27
donalfitz commentedHaving recently updated to MAMP pro 3.1 running on Yosemite Drush no longer worked. The Drupal site ran fine, command-line MySQL was ok, but Drush would not connect. I followed the recommendations in comment No. 13 above (mirrored elsewhere on different sites) but still no joy. Eventually, I did:
cd /tmp
sudo ln -s /Applications/MAMP/mysql/mysql.sock mysql.sock
This solved the problem for me, so I hope it is useful for others.
Comment #28
pianodavid commenteddonalfitz: Thank you so much! I tried everything in #13 too, but I had to do what you did to make it work. I am on OS X 10.9.5 (Mavericks) and it was the update to MAMP PRO 3.1 that made drush stop working.
Comment #29
kevinquillen commentedWhat if you are using Vagrant stacks and not MAMP? And why would Drush 6.5.0 work and not 7?
Comment #30
basvredelingI'm having similar issues as #26 and #27. Tried everything and then some.
My environment is a Homebrew installed Drush (7), just upgraded to Mamp 3.1 on Yosemite. Since the upgrade to 3.1 things are messed up on the drush front.
I reverted back to Drush 6 (brew switch drush 6.2.0) and now everything's fine. Changing localhost to 127.0.0.1 also works. But since I have 100s of settings.php files on my multiple development machines I won't just "change it to 127.0.0.1 and be done with it".
It looks like it's related to a combination of Drush 7 and MAMP 3.1 (php 5.6.6).
For now I'll run Drush 6 but that means no Drupal 8 development with Drush without switching versions.
Comment #31
fredklopper commentedSame problems after upgrading to MAMP 3.1. I use Drush version 6.5.0 (homebrew).
This symlink solved it for me:
/tmp/mysql.sock -> /Applications/MAMP/tmp/mysql/mysql.sock
Comment #32
nick.morahan commentedFor me it wasn't restricted to Drush 7 & Mamp 3.1, as I downgraded Drush to version 6 and still got problems. The symbolic link at #27 still isn't working, but for now #23 is doing the trick.
Comment #33
nick.morahan commentedThought I'd have another look at the symlink solution and got it working:
ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Comment #34
kevinquillen commentedDoes anyone know why that works though?
Comment #35
basvredeling#34 exactly! and why it suddenly stopped working.
Comment #36
kevinquillen commentedI don't use MAMP, I have a Vagrant stack, and Drush will not work like before, even when using the hostname.
Comment #37
basvredelingPerhaps Drush 7 is only trying to access the database via the network. That would explain why localhost doesn't work but an ip address does.
Comment #38
kevinquillen commentedSorry, the hostname as in something like 'local.mysite.com' in my hosts file, which maps to a Vagrant site - so it should work just the same as a local IP. Nothing does, though.
Drush 7 works from within the VM, but it should be able to work from both sides. I also tried using a Drush alias.
Comment #39
seanbfuller commentedSeems that the issue queue has moved over to github and this was marked as a dupe. However, since this is coming up for searches regarding localhost aliases for drush I thought I'd point people to a potentially relevant issue: https://github.com/drush-ops/drush/pull/546
In that thread is documented a new flag:
After setting up a new laptop and grabbing the latest version of drush, I was having issues getting drush to recognize the localhost alias. It kept trying to access the site via ssh, which resulted in this error: "ssh: connect to host example.local port 22: Connection refused." Adding that flag to my alias file under the local site entry got it working again. Hope that helps others who stumble across this thread.
Comment #40
mobius_time commentedWhen running Drush 6.6 and MAMP PRO 3.1, I couldn't get drush to work (PATH was set correctly, I could bring up mysql, etc.). Upgraded to MAMP PRO 3.2.1 and now drush works.
Comment #41
twooten commented@Fruit Fly, thank you for your work in figuring this out for a Linux Mint + XAMPP setup. This has been a pain for me for many months. I'm running the same setup (mostly) as you but just had no time to investigate.
sudo apt-get install php5-mysql did the trick for me.
Comment #42
torgospizzaThe fix in #23 worked for me as well, using the latest MAMP Pro on OSX Yosemite.
Comment #43
dave bruns commentedWith MAMP Pro 3.2.1, OSX 10.7.5, PHP 5.6.7
I ended up at this issue because I was installing a D7 site with drush make and couldn't get it to work. Finally I noticed that I could switch to Drush 7 with composer and it worked fine. But then, Drush en and dis failed with a "Drush was not able to start (bootstrap) the Drupal database. " message. Same commands worked perfectly with Drush 6.5.
Drush status with Drush 7 *looked* OK, but I didn't notice until later that it was missing things like
Drupal bootstrap : successful.After too long, I used the Drush --debug flag and noticed this in the output:
sh: mysql: command not foundSo, once I added this to .profile file, Drush 7 started to work fine:
export PATH=$PATH:/Applications/MAMP/Library/binStill not sure exactly why things worked well with Drush 6 vs Drush 7, but hopefully this is helpful to someone.
Helpful links:
http://www.webbykat.com/2012/06/solving-sh-mysql-command-not-found-mamp-...
http://drupal.stackexchange.com/questions/125345/drush-was-not-able-to-s...
http://www.razorsql.com/docs/support_mysql_mac_mamp.html
Comment #44
kevinquillen commentedFor people who don't use MAMP and get the same error, what is the resolution?
Comment #45
pio.fernandes commentedHi. I was getting some problems, and with --debug I saw that mysql was not being executed/recognized by drush, so my fix was to add mysql.exe path to the PATH var, in my Windows7. Hope it helps.
Comment #46
mhamed commentedHello
the same errors I had for the socket and drush --version 7
first solved the socket problem since i could not enter mysql from code :
Gave me the socket error:
1-here on this site i tried changing my /etc/my.cnf
changing this
socket=/var/lib/mysql/mysql.sockto thissocket=/var/mysql/mysql.socksince i ve got no lib folder.So my final my.cnf is
2-adding the symlink of the socket if it does not exist in :
/var/mysql/like this:sudo ln -s /Applications/MAMP/mysql/mysql.sock /var/mysql/mysql.sock3-This solved the mysql link but the problem of drush remain :
renamed the host :127.0.0.1
but has no effect the same error when want to enable a module.
-added
export PATH=/Applications/MAMP/Library/bin/:$PATHinto .bash_profile file .-but the error the same :
4-added as advised in the page
by #25
copying him in :
And with this drush 7 is in a good mood to brew
thanks
Comment #47
kevinquillen commentedDrush works on a VM if I specify the site alias now.
Comment #48
patrickwatzeels commentedMake sure that mysql is available in the PATH environment so you can access mysql everywhere. That solves the problem for me.
Comment #49
dasginganinjaFor those who were experiencing a database-related drush error such as:
I found on a non-MAMP system (Digital Ocean Ubuntu Droplet) that ~/.my.cnf existed with a password directive set. When I removed this file it was able to work. I found this odd because executing the output of drush sql-connect worked. I hope this helps somebody.
Comment #50
dobie_gillis commentedMy database settings are correct, and I'm getting this error with drush 7.0.0, php 5.3.10.
Is there a resolution for this issue?
EDIT: figured it out. I had to do
chmod a+x /etc/php5Comment #51
stolzenhain commentedComment #52
delacosta456 commentedHi
#13 .. 1) solved on mac os el captain with drupal 7.41 and drush v7 installed trought homebrew
Thanks
Comment #53
Andru commentedGot same errors as #15, able to download modules but not enable them.
Solution: had to CD to run on the correct local site directory (multi-site local install on Linux).
Went from /var/www/drupal7 to /var/www/drupal7/sites/example.com and then Drush enabled modules just fine.
Comment #54
bluesky_still commented[Site gone and replaced with gambling site] works for me!!!!
Comment #55
deajan commented#49 worked for me.
Had ~/.my.cnf file with password. Think this is a drush bug.
Comment #56
zakmahboub22 commentedComment #57
pascalli commentedHi bluesky_still your link in #54 did the trick for me. Cool !!!! Feel so releaved.
Comment #58
ragavendra_bn commentedComment #49 , made it work like a charm, just renaming or removing ~/.my.cnf helped on LAMP hosting.
Comment #59
knalstaaf commentedI didn't have to make any modifications at all, like changing localhost to 127.0.0.1. These three commands in Terminal solved the issue:
(Source)
Comment #60
mfuller526 commented#59 works perfectly. Thank you!!!
Comment #61
andraeray commentedI'm on windows here using composer and I was facing the same problem.
By adding mysql to my path from comment #43 fixed it.
I added it to my user environment variables.
Comment #62
zorz commentedIn my case (SQLSTATE[HY000] [2002] Connection refused) this article helped
https://modulesunraveled.com/blog/drush-not-working-mamp-heres-how-fix-it
added the following line in settings.php
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Comment #63
nitin.k commentedThanks #13. This link can help the needy one.
few commands to debug..
drush en statistics
drush status
Common messages:
"No Drupal site found, only 'Drush' cache was cleared."
"Drush was not able to start (bootstrap) the Drupal database."
In drupal root folder make sure we have correctly configured the database connection.
Use 127.0.0.1 in place of localhost, make changes in settings.php or in files which are included in settings.php.
MySql should be correctly linked to Drush which is done in case of Mamp. #13 and #43 works so well.
Comment #64
scott859 commented#43 Worked for me - thank you.
Comment #65
TristanTheKnightAway commentedJust wanted to pop in to say I couldn't resolve my drush7 issue using any of the above solutions until a colleague suggested just using drush6, which worked. Good article from Lullabot on how to add drush versions https://www.lullabot.com/articles/switching-drush-versions
Everything works now. For Drupal 7 sites, you can just use drush6 and for Drupal 8 sites you can just use Drupal console and life might be simpler.
p.s. using MAMP and PHP 7.1.1
Comment #66
trinhminhtriet commented#43 worked for me too.
Comment #67
hanskuiters commented#59 worked for me. Thanks.
Comment #68
pyim commentedchange database setting from 'localhost' to '127.0.0.1' in settings.php works for me. Jeez, took me 4 hours, why didn't I find this post sooner.
Comment #69
mikeytown2 commentedFYI Drush now requires the mysql client to be installed on your web head box. To see if it's there run
sudo find / -type f -name "mysql"If not then
CentOS/Redhat
sudo yum install mysqlUbuntu/Debian
sudo apt-get install mysqlWell that was fun.
Comment #70
davidandaman commentedI still have the same problem with AMPPS for MacOX Sierra.
iMac-de-David:i_resto_theme davidjulien$ drush omega-guard
The drush command 'omega-guard' could not be found. Run `drush [error]
cache-clear drush` to clear the commandfile cache if you have
installed new extensions.
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.59
Site URI : http://default
Database driver : mysql
Database hostname : 127.0.0.1
Database port :
Database username : root
Database name : irestolotus2018new2
PHP executable : /usr/bin/php
PHP configuration :
PHP OS : Darwin
Drush script : /Users/davidjulien/.composer/vendor/drus
h/drush/drush.php
Drush version : 7.4.0
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : /Applications/AMPPS/www/LOTUSBAR
Site path : sites/default
Any help would be appreciated.
Comment #71
joehudson commentedFor anyone still flummoxed by this issue, using D6 with PHP7 in cli, then the issue I found was that mysql_connect is not defined in PHP7 (replaced with alternatives).
This is why Drush reports mysql not installed, when using PHP7 on a D6 core, even though db modules are loaded.
So a quick fix to enable core update (D6LTS) was to use shims for mysql and also ereg.
I used https://github.com/dshafik/php7-mysql-shim/blob/master/lib/mysql.php
and
https://github.com/bbrala/php7-ereg-shim/blob/master/lib/ereg.php
Comment #72
joelpittetThanks @joehudson that worked for me I added them with composer:
composer require --dev dshafik/php7-mysql-shim bbrala/php7-ereg-shimComment #73
Dru18 commentedI came back in using MAMP (v 5.x) on Mac. I faced the same issue (D7) I used to have before.
As the above comment (somewhere), adding the following line in .profile (or .bash_profile) resolves my issue.
export PATH="/Applications/MAMP/Library/bin/:$PATH"
Then,
$ source ~/.profile
or $ source ~/.bash_profile
Tried both 127.0.0.1 and localhost: The hostname doesn't matter to me.
Comment #74
fonant commentedI came across this issue when trying to use drush in a chroot jail. Drush working fine, but couldn't connect to MySQL/MariaDB.
Mounting a copy of the mysql.sock file into the equivalent location in the chroot jail sorted the issue nicely.
Outline method, for a socket called
/var/lib/mysql/mysql.sock, and chroot at/var/chroot/jailname/:Then drush can connect using "localhost" instead of needing to change to "127.0.0.1".
Comment #75
kvu@csusm.edu commented@mikeytown2
I tried changing localhost to 127.0.0.1, but that didn't work. But reading your comment gives me an idea. I check my php7 modules and I was missing many:
I think the error goes away now, because I was missing php71w-mysqlnd
Comment #76
web226 commentedThanks for the tip AndraeRay
I'm using AMPPS on Windows 10 and adding the mysql path to the User path environment variables worked
i.e. D:\Ampps\mysql\bin