SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Drush was not able to start (bootstrap) the Drupal database.
Using fresh install of Drush drush-6.x-3.3.tar.gz and removed prior version
the update command retrieves the db connect settings etc
also using jailshell, PHP Version 5.2.13, MySQL 5.0.87, site is running D 6.16
I replaces some sensitive info with 'user'
user@decibelplaces.com [~/public_html/netsperience]# drush update
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [warning]
Drush was not able to start (bootstrap) the Drupal database. [error]
Hint: This error often occurs when Drush is trying to bootstrap a
site that has not been installed or does not have a configured
database.
Drush was attempting to connect to :
Drupal version : 6.16
Site URI : http://default
Database driver : mysqli
Database hostname : localhost
Database username : correct username
Database name : correct db name
Default theme : garland
Administration theme: garland
PHP configuration : /usr/local/lib/php.ini
Drush version : 3.3
Drush configuration:
Drupal root : /home/user/public_html/netsperience
Site path : sites/default
Modules path : sites/all/modules
Themes path : sites/all/themes
%paths : Array
You can select another site with a working database setup by
specifying the URI to use with the --uri parameter on the command
line or $options['uri'] in your drushrc.php file.
Command pm-update needs a higher bootstrap level to run - you will [error]
need invoke drush from a more functional Drupal environment to run
this command.
Command pm-update needs the following modules installed/enabled to [error]
run: update.
The drush command 'update' could not be executed. [error]
Comments
Comment #1
decibel.places commentedchange 'localhost' to '127.0.0.1' in $db_url in settings.php
#703454: Drush Bootstrap Problem Using Localhost in Settings.php file
I looked for a drush or mysql config solution so I would not have to change the settings.php for each site, didn't find one but I'm sure it exists
Comment #2
sanguis commentedjust wanted to say taht this worked for me as well
Comment #3
josedazagz commentedConfirmed. Solution from decibel.places did work for me too. Thank you very much.
Comment #4
amirtaiar commentedNot working for me. Have the samae issue
Comment #5
sanguis commentedamirtaiar: did you try the solution found in #1
Comment #6
aerozeppelin commentedThank you, this worked for me!
Comment #7
anewday commentedChanged the following in settings.php
$db_url = 'mysql://username:password@127.0.0.1/databasename';
It still doesn't work.
Comment #8
decibel.places commented@ anewday
I presume you put in the actual values for the databasename, user and password (?)
maybe try mysqli?
$db_url = 'mysqli://username:password@127.0.0.1/databasename';
also the db connection for D7 is an array, not a string; this thread pertains to Drupal 5.x and 6.x
Comment #9
bsnodgrass commentedIn my case I did not get any errors similar to "SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [warning]" and My Drush version is 4.5 which evidently still has issues with localhost vs. 127.0.0.1
However I am on a shared server for this dev site...
my ssh session to update my dev site:
I found another post referring to the first direction drush provided above "Command pm-update needs the following modules installed/enabled to run: update. [error]"
Hmmm took a look at a site where drush was working properly:
Noticed the difference localhost and 127.0.0.1 and two additional lines in the status
Database : Connected
Drupal bootstrap : Successful
I had heard of this before so I edited the settings.php database connect string to use 127.0.0.1 for the following results:
Life is good...
Thanks folks hope this helps someone.
Comment #10
bserem commentedIn my shared host, with Jailshell, drush stops working whenever I add a php.ini file in ~/drush.
Scenario and steps:
I install drush in ~/drush
I copy drush.ini from examples and change line 69 to:
disable_functions = ''Everything is fine, but I get out of memory errors. Changing the memory limit in drush.ini doesn't affect anything.
I add a php.ini with
memory_limit = 128Minside it.Drush stops working, it is now unable to bootstrap!
I can reproduce this on all of my shared servers!
Comment #11
henrikakselsen commented#1 worked for me also. Thx.
Comment #12
mar111 commentedI have this issue with :
7.x-5.0 ---- 2012-Mar-23
All-versions-5.x-dev ------ 2012-Apr-01
I tried to change localhost by number but does not work.
But it is working perfect with drush 4.5
7.x-4.5 ----- 2011-Aug-12
Comment #13
cainrus commentedI have same issue with:
These all pear version.
Comment #1 did not helped
Comment #14
jonhattanIf changing localhost to 127.0.0.1 won't fix for you this is probably other problem. Open a new issue with all relevant details.
Comment #16
trangunghoa commentedThank you bsnodgrass.
I have solved the problem.
Comment #17
lgomezma commentedIn case you have a multi-site installation and you have multiple settings.php files, just go to the site directory where the right settings.php is and run drush there.
Comment #18
matthewv789 commentedThank you lgomezma, #17 worked for me. Navigated to /sites/[sitename.local]/ where my relevant settings.php was, and was able to run drush from there. (I don't really have multiple sites, just a local settings file so I don't have to modify the default settings.php for the site pulled from git.)
Comment #19
pal4life commentedCan some one point to this issue discussion for Drupal 7?
Thanks
Comment #20
decibel.places commentedSet the path to drush in your drush path-aliases as explained in example.aliases.drushrc.php
I'm not sure whether both %drush and %drush-script are necessary, but since %drush-script defaults to "drush" or "drush.php" you need to specify it as "drush.bat" on a Windows environment.
my example with absolute (not relative) paths:
'path-aliases' => array(
'%drush' => '/home/decibelp/bin/drush',
'%drush-script' => '/home/decibelp/bin/drush/drush',
... more path-aliases: files etc.
),
Comment #21
hawkeye126 commentedI cannot find
$db_url
in /sites/default/settings.php or anywhere in the drupal or drush install folders.
I am running drupal 7.
What am I missing or doing wrong?
Please help, my site works fine but drush cannot access it:
[prompt]# drush pm-enable bootstrap
Command pm-enable needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command. [error]
The drush command 'pm-enable bootstrap' 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.28
Site URI : http://default
PHP executable : /usr/bin/php
PHP configuration : /etc/php.ini
PHP OS : Linux
Drush version : 7.0-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : {REMOVED}
Site path : sites/default
When I try to connect to mysql:
[prompt]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[prompt]# drush status
PHP executable : /usr/bin/php
PHP configuration : /etc/php.ini
PHP OS : Linux
Drush version : 7.0-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
I am on a linux vps with 1and1.
Thank you!
Comment #22
decibel.places commented@hawkeye126
In D7 the database connections are defined by an array, instead of the $db_url string that was used in D6
There's a very good Guided Tour of Drupal's settings.php for Drupal 7 by OSTraining
I recommend that you check it out, it might answer questions you don't know you have yet ;)
The pertinent part is changing the default setting to 'host' => '127.0.0.1'
If you continue to have issues with D7, please try to find an issue about this for D7, or start one yourself if you cannot find any appropriate one.
This is an old thread about D6.
Comment #23
raulmuroc commentedIt didn't work because mysql.exe was not there in the system PATH. So I added H:\xampp\mysql\bin to PATH and then it worked! (in Mac Os X usually in /usr/local/mysql/bin)
Comment #24
sparker888 commentedI struggled with this issue for a long time, and through reading many articles and forums, a lot of blood, sweat and tears, I finally figured out this solution:
NOTE: I am on Win 8.1, but most of these instructions came from various Win 7 installs and they still worked.
My Dev Environment: For the stack I'm using Dev Desktop from Acquia (I do NOT recommend DD2), Git for Windows (git bash), and Drush for Windows
There are several resources for installing Dev Desktop, Git, and Drush together, namely: http://friendlydrupal.com/screencasts/windows-tools-git-drush-acquia-dev... and I also found this helpful (but note differences below): http://wiki.drupalwxt.org/architecture/getting-started-win/
This last article also references this one which is very helpful when installing Drush for Windows: https://www.drupal.org/node/1843176
1. You MUST update your Environmental Variables User $PATH to include: C:\Program Files\acquia-drupal\mysql\bin;
2 You MUST also include several drush paths in the same User $PATH IF the drush installer didn't already do this for you (it usually does, but there are some reported problems on certain Windows installations)
Here is the exact code I use (including the one mentioned in 1. above):
C:\ProgramData\Drush\;C:Program Files (x86)\Drush\GnuWin32\bin;C:\Program Files (x86)\Drush\Php;C:\Program Files (x86)\Drush\cwRsync\bin;C:\Program Files\acquia-drupal\mysql\bin;
3. You MUST add a new entry in your hosts file (C:\Windows\System32\drivers\etc\hosts): 127.0.0.1 yoursitename
Note: If you have a site name such as yoursitename.localhost from when you configured/named your site in Dev Desktop, it DOES NOT MATTER. Keep the basic site name as shown above.
4. You MUST create a local drush alias for the site using the following format:
NOTE: In the URI, if your site is named mysite.localhost, change this to mysite.localhost here, but NOT in db-url
NOTE: If you are using root with no password in the database (not a good practice btw), you can leave out the password
5. Be sure and follow the naming convention for naming aliases: yoursitename.aliases.drushrc.php (typically you put the alias files in the ~/.drush/ folder, but there are other options that you can read about).
6. Assuming you're using sites/all/yoursitename, make sure and change default.settings.php to settings.php (no need to modify this one)
7. Open Git Bash (or close and re-start it)
8. Test to see that drush can read your aliases using:
drush sa(you should see @yoursitename and perhaps others in a list)
9. Next, test your alias is working using:
drush @yoursitename status(you should see a bunch of info related to your site with no errors)
If that works, you can test to make sure you're hooked up to the database by using:
drush @yoursite ccYou should get a list of 10 caches you can clear. Just choose one (like 1) and hit Enter. If that works, you should be in business
10. Navigate to your site directory and perform an update:
drush upIf all works correctly, drush will take you through the update process [success], and you have successfully connected to your database and updated your site through drush! xD
11. If you get an error related to missing the update module, you need to enable the core Update Manager module on your site.
If you have any problems between 8-11, try:
drush cc drushThis clears the drush cache and you can try the drush commands again. If that fails, try quitting and re-starting your git bash shell as well. If you are still receiving errors at this point, you need to go back and check to make sure everything is perfectly coded. The smallest thing (especially path settings or incorrect database paths, site name or credentials in the drush alias file) will break it.
Also, I renamed my folder in C:\Program Files (x86)\acquia-drupal\drush to 'old-drush' so Dev Desktops internal drush wouldn't interfere. I tried many things to make this drush work, and never succeeded, so I ditched it.
I'll try to answer any questions and update this procedure as needed. If there is something that I'm missing, doing wrong, or a better fix, please let me (and the community) know. However after weeks of trial and error and meticulous documentation, I believe this should be accurate. Good Luck!
Comment #25
bhupendra_kanojiya commentedThanks RaulMuroc.... #23 worked for drupal 7.
Comment #26
macmladen commentedNote to myself and (probably) other Mac users out there: when you install
mysqlfrom Oracle/Sun/MySQL from regular .DMG file, you will end up with temporary path tomysqlbeing in path but upon restart path will be lost.So you have to make symbolic link to binaries, most importantly,
mysql mysqldump.Upon installation, do the following in terminal:
If you need other commands (and there are many useful there in
/usr/local/mysql/bin/) link them too. This links shouldn't break even uponmysqlupgrade.Does anyone think
MariaDBandbrewworks better?Comment #27
Juanpgs commented#23 , it works!
Comment #28
gdev2018 commentedto #24 by sparky888.
Hi! Add to your collection:
12. Edit Sqlpgsql.php (...\composer-root\vendor\drush\drush\lib\Drush\Sql\Sqlpgsql.php )
line 9:
//public $query_extra = "--no-align
--field-separator='\t'--pset tuples_only=on";public $query_extra = "--no-align --pset tuples_only=on";
line 45:
//$environment = "PGPASSFILE={$pw_file} ";
$environment = "SET PGPASSFILE={$pw_file} & ";
(Windows 7, drush 8.1-dev)
Good luck!
Comment #29
dblais commentedI'm inside a CPANEL/WHM environement.
You can also check if you have the file ".my.cnf" inside your home directory. If yes, mysql will use the user/password inside this file event if Drush use the good one. Good to know!
Try to rename or delete your ".my.cnf".
Comment #30
ltrainJust wanted to add that for MAMP users, these are the symbolic links you need to add:
Thanks all!
Comment #31
speedyqueenie commentedDid #1 - no dice. Keeping the 127.0.0.1 setting, I tried #30 and it worked!
Comment #32
knalstaaf commentedI was getting this back:
#30 solved it - cheers!
Comment #33
MarkBGH commentedJust piling on to say that #30 was the ticket!
Comment #34
W.M. commentedWhat solved a similar issue for me under Windows was to add the \mysql\bin directory to PATH
Comment #35
zorphdark#34 solved adding `mysql/bin` path to Windows PATH. thanks :)
Comment #36
ezkhimo commentedI'm under WAMP, Drupal 8 / Drush 8 and the error occured when trying to
drush runserveran SQLite-based installation. The path-related comments gave me the obvious hint that I had to add the path to my sqlite3 executable to Windows PATH, accordingly. It worked after that. Thanks!Comment #37
sozonov commented#30 solved the problem! Thanks!
Comment #38
frazacand this solved for xampp ;)
thanks @itrane with #30
Comment #39
dendrmx commented#26 Works great for me.
Thank's MacMladen!
Comment #40
maitak commentedThis link worked for me https://modulesunraveled.com/blog/drush-not-working-mamp-heres-how-fix-it. For D8.
Comment #41
yosia_ken commented#23 works for me, thanks!!
Comment #42
ronit29 commented#30 works perfectly for me with XAMPP on Ubuntu
cd /usr/local/bin
sudo ln -s /opt/lampp/bin/mysql
sudo ln -s /opt/lampp/bin/mysqldump
Comment #43
omrmankar#1 works for me thanks in Drush Version: 8.1.16
Comment #44
drupalbabaji commented#23 worked for me
Comment #45
serialmother commented#1 works for me. Thank you Decibel.places!
Comment #46
ashique12009 commented#23 worked for me, thanks.
Comment #47
kunal_singh commented#23 worked for me, Thank you.
Comment #48
bisw commented#23 worked for me. Thank you very much.
Comment #49
santosh8943 commented#1 worked for me. Thank you Decibel.places!
Just changed localhost to 127.0.1 in file located at sites/default/settings.php
Comment #50
jweirather commentedIn my case I was running a production environment with a separate database server. Drush required mysql-client to be installed on the same server it's running on, so I had to install the mysql-client from the command line:
sudo apt install mariadb-clientin my case. Noting that your command and specific client may vary depending on your setup and whether you're using mysql or mariadb.Comment #51
leolopre commentedafter executing the command
yum install mysqldrush works fineComment #52
timwhelanatl commentedI found this to work for me with MAMP,
sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysqlComment #53
skatheeth commented#23 worked for me! Thank you very much!
Comment #54
loopy1492 commentedI was attempting to spin up an old d7 site locally with the prod db and got this error. As it turns out, the last time modules and core was updated on production, updatedb hadn't been run. After getting the correct site uri set in local.drushrc.php, running `drush updatedb` cleared this up.