I'm installing a drupal site on a cloud, which has a remote database cloud service.

But I found that drupal seems ignore the host I give and use unix_socket to connect the remote database.

Here is the Set up database screen during installation. I'm sure database name, username and password are correct. I have try ip address and domain name in the host field. The socket field leaves empty.

enter image description here

And I got:

Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] Invalid argument.

I'm not familiar with PHP and mysql, I don't know a better way to find out what Invalid argument is. I So I do some grep and add some print_r() in [drupaldir]/includes/database/database.inc:

// Call PDO::__construct and PDO::setAttribute.
parent::__construct($dsn, $username, $password, $driver_options);

This is what I got (add a few line break, and replace the real name and password):

Array ( [1000] => 1 [20] => 1 [3] => 2 )

Is this mean, Drupal installation ignores the host what ever I give and just use unix_socket even it's empty?

  • 1
    You should file an issue on drupal.org for this. When you 'hack core', you live dangerous, because you will have to reapply this patch every time you update drupal core - and will probably forget eventually. The better way to fix this in your case is, to fix the entry in your settings.php file. It is located in sites/default or sites/example.com. And to make it won't happen to the next person, file an issue.
    – Ursula
    Commented Jan 9, 2014 at 7:20
  • Please post answers as an answers, not as edits to a question. Answer still available in revision history, should you want to copy-paste it from there.
    – Mołot
    Commented Jan 9, 2014 at 8:18
  • It just looks like unix_socket=; is an empty string and not used in that output. Make sure your remote firewall accepts connections on the mysql port from your host/ip address. Commented Jan 9, 2014 at 8:29
  • @DavidThomas See this revision for OPs solution.
    – Mołot
    Commented Jan 9, 2014 at 8:29
  • David,I am having a problem connecting to a remote MySQL server. Logging on to the remote MySQL from the Drupal box directly works but Drupal can't connect to the db. setting.php looks good. I am hesitant to change core. What additional settings in settings.php would circumvent this problem? The Drupal box doesn't have mysql.sock installed.
    – Mike Jr
    Commented Jan 14, 2015 at 19:33

1 Answer 1


I think I have located this issue. includes/database/mysql/database.inc, line 32:

// The DSN should use either a socket or a host/port.
if (isset($connection_options['unix_socket'])) {// will be TRUE if unix_socket is ''
  $dsn = 'mysql:unix_socket=' . $connection_options['unix_socket'];
else {
  // Default to TCP connection on port 3306.
  $dsn = 'mysql:host=' . $connection_options['host'] . ';port=' . (empty($connection_options['port']) ? 3306 : $connection_options['port']);

$connection_options['unix_socket'] will be an empty string if we leave it empty on the page. So this test will be TRUE. Replace isset with !empty solve this issue:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.