Drush not connecting to database
| Project: | Drush |
| Version: | 5.x-1.3 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | won't fix |
Jump to:
Drush does not seem to be connecting to the database. I'm actually getting HTML on the command line.
This is what it looks like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Unable to connect to database server</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="all">@import "/misc/maintenance.css";</style>
<style type="text/css" media="all">@import "/modules/system/defaults.css";</style>
<style type="text/css" media="all">@import "/modules/system/system.css";</style>
<link rel="shortcut icon" href="/misc/favicon.ico" type="image/x-icon" />
</head><body><h1>Unable to connect to database server</h1>
<!-- begin content -->
<p>If you still have to install Drupal, proceed to the <a href="/install.php">installation page</a>.</p>
<p>If you have already finished installing Drupal, this either means that the username and password information in your <code>settings.phpThe MySQL error was: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2).
Currently, the username is root and the database server is localhost.
- Are you sure you have the correct username and password?
- Are you sure that you have typed the correct hostname?
- Are you sure that the database server is running?
For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.
I did move this site between servers, and it still seems to be working fine on the first server. I did update the sites/default/settings.php to reflect the new database, and the site seems to work fine. Not sure why Drush is doing this.
Also, I call Drush from the drupal root with ./sites/all/modules/drush/drush.php.
Is there some where that Drush is caching the database URL?

#1
This is the full output of the script, without the PHP tags obviously....
<?php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Unable to connect to database server</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="all">@import "/misc/maintenance.css";</style>
<style type="text/css" media="all">@import "/modules/system/defaults.css";</style>
<style type="text/css" media="all">@import "/modules/system/system.css";</style>
<link rel="shortcut icon" href="/misc/favicon.ico" type="image/x-icon" />
</head><body><h1>Unable to connect to database server</h1>
<!-- begin content -->
<p>If you still have to install Drupal, proceed to the <a href="/install.php">installation page</a>.</p>
<p>If you have already finished installing Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can't connect to the MySQL database server. This could mean your hosting provider's database server is down.</p>
<p>The MySQL error was: <em>Can't connect to local MySQL server through socket '/var/mysql/mysql.sock (2)</em>.</p>
<p>Currently, the username is <em>root</em> and the database server is <em>localhost</em>.</p>
<ul>
<li>Are you sure you have the correct username and password?</li>
<li>Are you sure that you have typed the correct hostname?</li>
<li>Are you sure that the database server is running?</li>
</ul>
<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>
<!-- end content -->
</body></html>
?>
#2
I assume that you have no problems connecting to the database with the regular drupal installation.
I had a similar problem, the solution was that I had to point command line PHP to the php.ini file used by the apache php to enable database support.
This is done with the -c attribute
php -c /path/to/php.ini /path/to/drush.phpthe path to the php.ini can be found allmost at the top running the command php -i, or alternatively making a simple php page that looks like this:
<?phpphpinfo();
?>
This might help solve this problem, but I did not get exactly the same error you have. My error was that php claimed I had not activated any database modules.
#3
http://www.raincitystudios.com/blogs-and-pods/steve-krueger/how-use-drus...
Just saw this, and confirms the same thing Vidar mentioned. I haven't tried it yet, but I am sure this is what the problem is. Maybe I'll try to cook up something to add to the docs for this.
#4
Automatically closed -- issue fixed for two weeks with no activity.
#5
Having the same issue with 6.x-1.x-dev
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="" lang="" dir="ltr">
<head>
<title>Site off-line | Drupal</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/misc/favicon.ico" type="image/x-icon" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/defaults.css?0" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system.css?0" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system-menus.css?0" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/maintenance.css?0" />
<link type="text/css" rel="stylesheet" media="all" href="/themes/garland/style.css?0" />
<link type="text/css" rel="stylesheet" media="all" href="/themes/garland/minnelli/minnelli.css?0" />
<link type="text/css" rel="stylesheet" media="print" href="/themes/garland/print.css?0" />
<!--[if lt IE 7]>
<link type="text/css" rel="stylesheet" media="all" href="/themes/garland/fix-ie.css" /> <![endif]-->
</head>
<body>
<!-- Layout -->
<div id="header-region" class="clear-block"></div>
<div id="wrapper">
<div id="container" class="clear-block">
<div id="header">
<div id="logo-floater">
<h1><a href="/" title="Drupal"><img src="/themes/garland/minnelli/logo.png" alt="Drupal" id="logo" /><span>Drupal</span></a></h1> </div>
</div> <!-- /header -->
<div id="center"><div id="squeeze"><div class="right-corner"><div class="left-corner">
<h2>Site off-line</h2> <div class="clear-block">
<p>The site is currently not available due to technical problems. Please try again later. Thank you for your understanding.</p><hr /><p><small>If you are the maintainer of this site, please check your database settings in the settings.php file and ensure that your hosting provider's database server is running. For more help, see the <a href="http://drupal.org/node/258">handbook</a>, or contact your hosting provider.</small></p><p><small>The <em>mysql</em> error was: <em>Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)</em>.</small></p> </div>
<div id="footer"></div>
</div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->
</div> <!-- /container -->
</div>
<!-- /layout -->
</body>
</html>
mysql is running fine for my site.
#6
Figured out the solution to this problem - I needed to update my settings.php to set the host for mysql to 127.0.0.1 instead of localhost to be able to access mysql from command line.
#7
I had this same problem with version 5.
I am running MAMP on OS X so there was more than one version of php on my machine and the one I wanted was not in my path.
The solution was to specify the MAMP version of php in the alias. the line in .bash_profile looked like this:
alias drush='/Applications/MAMP/bin/php5/bin/php ~/Documents/websites/public_html/drupal-5.7/sites/all/modules/drush/drush.php -r ~/Documents/websites/public_html/drupal-5.7'and i used the -l switch to specify the site.
#8
#9
MAMPIf using MMAP, your socket file is not where mysql expects so that could be an issue as well. This is basically a local config problem, not drush.
#10
I think the issue now is about how to properly document this.
#11
Potentially not... I have a very similar problem, but with a different MySQL error. NO idea what's causing this. This is on a *nix server in a shared hosting environment, and Drush works in this exact account with a D5 setup.
I get:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
... stuff...
<div id="center"><div id="squeeze"><div class="right-corner"><div class="left-corner">
<h2>Site off-line</h2> <div class="clear-block">
<p>The site is currently not available due to technical problems. Please try again later. Thank you for your understanding.</p><hr /><p><small>If you are the maintainer of this site, please check your database settings in the settings.php file and ensure that your hosting provider's database server is running. For more help, see the <a href="http://drupal.org/node/258">handbook</a>, or contact your hosting provider.</small></p><p><small>The <em>mysqli</em> error was: <em>Unable to use the MySQLi database because the MySQLi extension for PHP is not installed. Check your php.ini to see how you can enable it.</em>.</small></p> </div>
<div id="footer"></div>
</div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->
</div> <!-- /container -->
</div>
<!-- /layout -->
</body>
</html>
I have no idea where this is coming from, as I've never used, attempted to use, or even typed "mysqli" before in my life, afaik.
#12
You don't have to type mysqli - Drupal detects that for you and uses it if available. So, you need to go to the settings.php that is in effect for this drush request and edit the line starting with $db_url and use mysql instead of mysqli
This whole thread comes down to people not configuring their command line php properly which is really easy to do. Unfortunately, fixing this out of scope for this module. It does not help that MAMP and maybe others do some non-standard stuff.
#13
WOW. I wouldn't have thought of that in a month. I'm confused why I don't have this same problem with D5 tho - is the default connection string not the same? I have run a D5 install in exactly the same account, without this problem. Also, the rest of the site works just fine with the string like that, which seems weird...
At the *very* least, I think a mention of this deserves an entry in the README? The command line php stuff might be "really easy", but there is not a centralised place for these weird caveats, so people don't know about them. I asked half a dozen times about this on IRC with no useful response (not for want of people trying). Perhaps this is something that needs to be addressed?
Many thanks.
#14
Many providers give you what is known as a "jail shell"
When in this shell you can't use localhost as you don't have direct access to the MySQL socket. This is why you need to use a hostname of 127.0.0.1 so MySQL is accessed via TCP instead of trying to access via the socket.
Steve
HotDrupal - Drupal Friendly Hosting
#15
Another issue for me that was PHP/MySQL/MAMP related was that in setting.php, I don't have to specify the port that MySQL is running on for Drupal to work. I do have to specify it for drush to work, however. So I had to specify :8889 in my $db_url.