Problem/Motivation

There are several cases when Drupal can get "2002 Connection refused" error:

1. The 'unix_socket' option is set in settings.php and the socket is not accessible.
SQLSTATE[HY000] [2002] No such file or directory

2. The 'host' option is empty or set to 'localhost', which means to use default Unix socket, but socket is not accessible.
SQLSTATE[HY000] [2002] No such file or directory

3. There is an issue with accessing the server via TCP/IP:
3.1. Host name could not be resolved:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve

3.2. Host is not accessible.

3.3. Host is accessible, but connection on specified port refused:
SQLSTATE[HY000] [2002] Connection refused

3.4. I'm sure there are more cases.

Sometimes it takes significant time to discover the root cause of the error (especially for unexperienced developers). It would be great if Drupal provided more informative messages for MySQL error 2002. Perhaps with some tips how to resolve the issue.

Proposed resolution

The proposal is to introduce special exception class for MySQL 2002 error and provide additional information in error message.

Remaining tasks

Perhaps there will be a follow-up issues for pgsql and sqlite.

CommentFileSizeAuthor
#122 reroll_diff.txt3.06 KBravi.shankar
#122 2610858-122.patch9.16 KBravi.shankar
#116 2023-03-15 13_26_33-Hyper.png10.63 KBgrevil
#116 2023-03-15 13_25_42-Hyper.png10.91 KBgrevil
#116 2023-03-15 13_24_42-Hyper.png15.59 KBgrevil
#112 2610858-nr-bot.txt147 bytesneeds-review-queue-bot
#106 interdiff_103-106.txt536 bytesravi.shankar
#106 2610858-106.patch9.21 KBravi.shankar
#104 interdiff-2610858-88-104.txt5.95 KBkapilv
#103 interdiff-2610858-88-103.patch5.95 KBmohit_aghera
#103 2610858-103.patch9.22 KBmohit_aghera
#90 interdiff_84-88.txt2.02 KBshubham.prakash
#88 2610858-88.patch4.52 KBshubham.prakash
#87 2610858-87.patch4.02 KBshubham.prakash
#84 2610858-84.patch4.53 KBravi.shankar
#82 interdiff-2610858-78-82.txt4.77 KBMadhura BK
#82 connection-refused-error-2610858-82.patch4.55 KBMadhura BK
#78 2610858-78.patch3.68 KBravi.shankar
#76 2610858-76.patch4.31 KBravi.shankar
#70 drupal-mysql-connection-refused-message-2610858-70-D8.patch4.26 KBasvira
#69 mysql_connectivity-2610858-69.patch3.36 KBvacho
#56 mysql_connectivity-2610858-56.patch3.37 KBcameron tod
#53 mysql_connectivity-2610858-53.patch2 KBcameron tod
#52 mysql_connectivity-2610858-52.patch1.97 KBcameron tod
#38 mysql_connectivity-2610858-38.patch1.14 KBcilefen
#38 interdiff.txt883 bytescilefen
#34 database_connectivity-2610858-34.patch1.21 KBcilefen
#31 database_connectivity-2610858-31.patch4.08 KBcilefen
#26 interdiff.txt1.68 KBcilefen
#26 database_connectivity-2610858-26.patch1.1 KBcilefen
#24 database_connectivity-2610858-24.patch966 bytescilefen
#18 database_connectivity-2610858-18.patch1.23 KBkostajh

Issue fork drupal-2610858

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rgracia created an issue. See original summary.

asghar’s picture

Hi

I have configured the fresh Drupal-8.0.0-rc3 and Drush-8.0.0-rc3 versions. Run the multi commands and your mentioned commands but could not produce the errors.

asghar’s picture

Sorry I forgot to mention OS and php version:
OS X EI Capitan
PHP 5.6.10 (cli) (built: Jun 12 2015 10:07:24)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

aspilicious’s picture

Same problem on D8 head

dawehner’s picture

Isn't that what happens if you have a broken settings.php with wrong credentials?

kostajh’s picture

@dawehner that's right, but an easier to grok error message would be oh-so-welcome! I spent 30 minutes trying to figure this out in setting up a site on a CI environment. Turns out I had to set `127.0.0.1` instead of `localhost` in the MySQL host setting.

dawehner’s picture

@kostajh
Interesting I have seen this in some real world as well. Did we something broke about that?
Yeah I have no idea why the PDO exception isn't that helpful.

rgracia’s picture

Thanks for your replies guys. Here's a bit more info. The first try I created a settings.php myself as I was unaware the installation script now creates one if needed. So trashed the install and started again letting D8 generate it. Here is the output of said settings.php with comments omitted for brevity:

<?php

$databases = array();

$config_directories = array();

$settings['hash_salt'] = 'OAIsjv6ASMbCrmjS6-uaopTfWxtF7lZ8roxSiAQydo4slRpFThTlHfzzK4ExINB_6vuNnQoIaw';

$settings['update_free_access'] = FALSE;

$settings['container_yamls'][] = __DIR__ . '/services.yml';

$databases['default']['default'] = array (
  'database' => 'd8',
  'username' => 'root',
  'password' => 'root',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);
$settings['install_profile'] = 'standard';
$config_directories['sync'] = 'sites/default/files/config_ff_zmcXYP9FjF9fW0LcDnHKFhj_IrcVC0f6RmH6QNiFaIFinzt1x6-n6lrYZfsOyik5Ab7tTcQ/sync';

Again, setup El Cap 10.11.2 Beta (15C27e), MAMP 3.4, PHP 5.6.10, Drupal 8.0.0-rc3 and Drush 8.0.0-rc3.

UPDATE: I am getting same results with Drupal 8.0.0-rc1, Drupal 8.0.0-rc2 as well.

aspilicious’s picture

yes fresh installatie works

subson’s picture

Changing your localhost to 127.0.0.1 works for me.

cameron tod’s picture

Issue summary: View changes

If you found this page from a Google search, double check that your database credentials are correct in settings.php or settings.local.php.

In my case, everything worked fine in drush, but I was getting a "The website encountered an unexpected error. Please try again later." via Apache/PHP under MAMP.

I use a custom settings.local.php, and as it turns out, I have env vars setup in my cli but not in Apache.

Logged errors looked like this:

[26-Nov-2015 22:23:05 Europe/London] PDOException: SQLSTATE[HY000] [2002] No such file or directory in /Users/cameron.tod/Sites/q8/docroot/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 83
[26-Nov-2015 22:25:42 Europe/London] PDOException: SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'q8' in /Users/cameron.tod/Sites/q8/docroot/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 83

Maybe #1409108: Improve "Failed to connect to database" Error message is a good issue to use to clean up error output?

cameron tod’s picture

Title: Unable to run Drush commands with Core 8.0.0-rc3 and Drush 8.0.0-rc3 » Database connectivity issues give unhelpful error message
Version: 8.0.0-rc3 » 8.0.0
Issue summary: View changes
cameron tod’s picture

Issue summary: View changes
cameron tod’s picture

Issue summary: View changes
cameron tod’s picture

bechtold’s picture

I just arrived here as well using google.

My eror message:

exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in                               [error]
.../drupal-8/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php:146
Stack trace:

On
OSX 10.10.5
PHP 5.6.10
with a MAMP Pro setup.

The problem for me was the
'host' => 'localhost',.
Replacing it with
'host' => '127.0.0.1',
resolved the issue.

Took me a while to figure this out since the error message didn't help :-)

cilefen’s picture

Version: 8.0.0 » 8.0.x-dev
Component: other » database system
kostajh’s picture

Status: Active » Needs review
StatusFileSize
new1.23 KB

Here's a patch that changes the example from `localhost` to `127.0.0.1`.

bechtold’s picture

Status: Needs review » Needs work

I think this issue is asking about better error message and the patch is not solving this.

Also I got this error on a d7 install today that worked fine before #dcvie.
But only in drush, the page itself did work fine.
So maybe updating drush (which i did on the weekend) introduced this bug for me.

dawehner’s picture

Yeah this would be indeed way more helpful, even its also odd that localhost is no longer possible to use.

jorgediazhav’s picture

For MAMP, add this:

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'host' => '127.0.0.1',

It worked for me.

Best!!!

rgracia’s picture

Thank you all. jorgediazhav, your suggestion fixed it for me. Awesome!

cilefen’s picture

Re #20 it is probably because:

" A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost."

http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html

cilefen’s picture

Status: Needs work » Needs review
Issue tags: -drush
StatusFileSize
new966 bytes

This should be an improvement. The problem with the confusing error is:

  • It appears to happen in the wrong place (PhpArrayContainer) because of a call to call_user_func_array() in PhpArrayContainer
  • The MySQL client throws 'PDOException: SQLSTATE[HY000] [2002] No such file or directory' when 'localhost' is configured. See #23. This is out-of-scope for Drupal to fix.

This patch catches the exception earlier and rethrows a better exception in the correct place. Example:

[Fri Jan 29 15:11:16.794406 2016] [:error] [pid 73545] [client ::1:63598] Drupal\\Core\\Database\\DatabaseExceptionWrapper: exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Connection refused' in /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php:147\nStack trace:\n#0 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(147): PDO->__construct('mysql:host=127....', 'root', '', Array)\n#1 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Database.php(381): Drupal\\Core\\Database\\Driver\\mysql\\Connection::open(Array)\n#2 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Database.php(171): Drupal\\Core\\Database\\Database::openConnection('default', 'default')\n#3 [internal function]: Drupal\\Core\\Database\\Database::getConnection('default')\n#4 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(83): call_user_func_array('Drupal\\\\Core\\\\Dat...', Array)\n#5 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/Container.php(181): Drupal\\Component\\DependencyInjection\\PhpArrayContainer->createService(Array, 'database')\n#6 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(268): Drupal\\Component\\DependencyInjection\\Container->get('database', 1)\n#7 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(66): Drupal\\Component\\DependencyInjection\\PhpArrayContainer->resolveServicesAndParameters(Array)\n#8 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/Container.php(181): Drupal\\Component\\DependencyInjection\\PhpArrayContainer->createService(Array, 'cache.container')\n#9 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/DrupalKernel.php(493): Drupal\\Component\\DependencyInjection\\Container->get('cache.container')\n#10 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/DrupalKernel.php(818): Drupal\\Core\\DrupalKernel->getCachedContainerDefinition()\n#11 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/DrupalKernel.php(441): Drupal\\Core\\DrupalKernel->initializeContainer()\n#12 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/DrupalKernel.php(636): Drupal\\Core\\DrupalKernel->boot()\n#13 /Users/cjm/Sites/drupal8x/index.php(19): Drupal\\Core\\DrupalKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#14 {main} in /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 83

Access denied:

[Fri Jan 29 15:20:18.941479 2016] [:error] [pid 71237] [client ::1:63707] Drupal\\Core\\Database\\DatabaseExceptionWrapper: exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'roots'@'localhost' (using password: NO)' in /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php:147\nStack trace:\n#0 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(147): PDO->__construct('mysql:host=127....', 'roots', '', Array)\n#1 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Database.php(381): Drupal\\Core\\Database\\Driver\\mysql\\Connection::open(Array)\n#2 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Database.php(171): Drupal\\Core\\Database\\Database::openConnection('default', 'default')\n#3 [internal function]: Drupal\\Core\\Database\\Database::getConnection('default')\n#4 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(83): call_user_func_array('Drupal\\\\Core\\\\Dat...', Array)\n#5 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/Container.php(181): Drupal\\Component\\DependencyInjection\\PhpArrayContainer->createService(Array, 'database')\n#6 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/De
...

Socket not found (with 'localhost' config instead of '127.0.0.1', which means the server is not running or no socket exists-which could be various reasons):

[Fri Jan 29 15:22:04.010042 2016] [:error] [pid 73545] [client ::1:63734] Drupal\\Core\\Database\\DatabaseExceptionWrapper: exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php:147\nStack trace:\n#0 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(147): PDO->__construct('mysql:host=loca...', 'root', '', Array)\n#1 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Database.php(381): Drupal\\Core\\Database\\Driver\\mysql\\Connection::open(Array)\n#2 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Core/Database/Database.php(171): Drupal\\Core\\Database\\Database::openConnection('default', 'default')\n#3 [internal function]: Drupal\\Core\\Database\\Database::getConnection('default')\n#4 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(83): call_user_func_array('Drupal\\\\Core\\\\Dat...', Array)\n#5 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/Container.php(181): Drupal\\Component\\DependencyInjection\\PhpArrayContainer->createService(Array, 'database')\n#6 /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(268): Drupal\\Component\\DependencyInjection\\Container->ge
...
dawehner’s picture

+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
@@ -143,7 +143,12 @@ public static function open(array &$connection_options = array()) {
+    catch (\PDOException $e) {
+      throw new DatabaseExceptionWrapper($e);
+    }

IMHO We should explain why we are doing that here.

cilefen’s picture

StatusFileSize
new1.1 KB
new1.68 KB

@dawehner and I found we could wrap the offending call_user_func_array() and deal with all underlying exceptions. The stack traces look the same as in #24.

dawehner’s picture

+++ b/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php
@@ -80,7 +80,15 @@ protected function createService(array $definition, $id) {
+        throw new \Exception($e);

that code certainly breaks, it should be throw $e

cilefen’s picture

@dawehner Huh-Did you try that? It results in the same situation as without any patch.

cilefen’s picture

I agree how #26 should not work though. It must be a toString happening.

cilefen’s picture

Status: Needs review » Needs work

Stuffing a stack trace into an exception message won't work.

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new4.08 KB

Another way to do this, and for all database drivers, is to catch the exception where it occurs and rethrow an exception that won't be caught as a PDOException higher up.

Status: Needs review » Needs work

The last submitted patch, 31: database_connectivity-2610858-31.patch, failed testing.

artfrick’s picture

[Sun Jan 31 12:28:30.844457 2016] [fcgid:warn] [pid 11232:tid 920] [client 127.0.0.1:63683] mod_fcgid: stderr: Drupal\\Core\\Database\\DatabaseConnectionException: SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'drupal8x' in C:\\Users\\alj456\\Sites\\devdesktop\\drupal8x\\core\\lib\\Drupal\\Core\\Database\\Driver\\mysql\\Connection.php on line 150

This is now the exception with the patch from #31 applied. Is this better? Personally, I think it's helpful to have the actual line in the file, however, we've managed to lose the fact that it's a PDO exception.

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.21 KB

This version provides some help when people have used "localhost" for the database connection, and the socket does not exist, and the confusing error that results.

Drupal\\Core\\Database\\DatabaseExceptionWrapper: SQLSTATE[HY000] [2002] No such file or directory (This message indicates that MySQL is configured to use a socket that is not available. See the MySQL client documentation for the meaning of "localhost".) in /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 83

Next, as for this not-very-confusing error in the issue summary:

PDOException: SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'drupal' in /core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 83

I think that is quite clear and doesn't require fixing.

dawehner’s picture

It would be nice to document what this issue changes, so its clear that this improves the situation.

artfrick’s picture

Title: Database connectivity issues give unhelpful error message » MySQL connectivity error when a socket is not found is confusing
Issue summary: View changes
Issue tags: -Needs issue summary update

Status: Needs review » Needs work

The last submitted patch, 34: database_connectivity-2610858-34.patch, failed testing.

cilefen’s picture

Issue summary: View changes
StatusFileSize
new883 bytes
new1.14 KB

This is a lightweight approach to the specific error.

PDOException: SQLSTATE[HY000] [2002] No such file or directory. (MySQL is configured to use "localhost" and the socket file was not found.) in /Users/cjm/Sites/drupal8x/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 83
cilefen’s picture

Status: Needs work » Needs review

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wooody’s picture

Thanks jorgediazhav #21 works with me.

aangel’s picture

@jorgediazhav Your suggestion worked for me, too.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nottaken’s picture

Thanks @jorgediazhav. #21 worked for me too.

Status: Needs review » Needs work

The last submitted patch, 38: mysql_connectivity-2610858-38.patch, failed testing.

dawehner’s picture

Should we expand it to telling people that your mysql server might simply not be started in the first place, like after a reboot?

xiwar’s picture

Hi, i'm Matt Lambert from Redweb. I'm going to re-roll this patch.

xiwar’s picture

I could apply the patch, so no reroll is needed.

xiwar’s picture

Status: Needs work » Needs review
daffie’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Needs review » Needs work

Hi Matt, my mistake. #728702: Visiting index.php should redirect to install.php if settings.php already has database credentials but database is empty. has been applied to Drupal 8.3 and so should the patch from this issue. Can you try again?

cameron tod’s picture

Status: Needs work » Needs review
StatusFileSize
new1.97 KB

I've moved this into a custom exception now to maintain the pattern in 8.3.x.

cameron tod’s picture

StatusFileSize
new2 KB

Gah, forgot a return statement.

Status: Needs review » Needs work

The last submitted patch, 53: mysql_connectivity-2610858-53.patch, failed testing.

daffie’s picture

The patch looks good. I do have a problem with it:

+++ b/core/lib/Drupal/Core/Database/DatabaseConnectionRefusedException.php
@@ -0,0 +1,19 @@
+    $message .= ' MySQL was attempting to connect via a socket, but the socket file could not be found. If you are seeing this exception on a local development machine, try change your database server to an IP instead of a hostname.';

The problem that I have with this is that other databases can have the same problem and this message is specific for MySQL.

I was wondering if we also should add the same for PostgreSQL. The error code for a refused connection on PostgreSQL is 10061. What do you think @Cameron Tod?

cameron tod’s picture

Title: MySQL connectivity error when a socket is not found is confusing » Add informative error message for 'Connection refused' errors in MySQL and PostgreSQL
Status: Needs work » Needs review
Issue tags: -Needs reroll +PostgreSQL, +MySQL
StatusFileSize
new3.37 KB

The last patch had a fatal error in it - that's what I get for using vim and not PHPStorm and not testing.

I've also added PostgreSQL handling. I don't know a lot about PostgreSQL so this is based on some educated guess work. If the tests pass I think its worth the PostgreSQL maintainers taking a look.

mradcliffe’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
    @@ -35,6 +36,12 @@ class Connection extends DatabaseConnection {
    +  const CONNECTION_REFUSED = '10061';
    
    @@ -135,6 +142,11 @@ public static function open(array &$connection_options = array()) {
    +      if (static::getSQLState($e) == static::CONNECTION_REFUSED) {
    

    It is very hard for me to trigger this test as a vary narrow use case of ipv6/ipv4 connection issues.

    If I try an invalid host on the box, I get 08006.

  2. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
    @@ -35,6 +36,12 @@ class Connection extends DatabaseConnection {
    @@ -135,6 +142,11 @@ public static function open(array &$connection_options = array()) {
    

    I think the doc block in Drupal\Core\Database\Database::openConnection should be updated with @throws \Drupal\Core\Database\DatabaseConnectionRefusedException.

Thinking about this some more... I am not sure if PostgreSQL logic is solving the same problem as MySQL for the original issue.

1. In MySQL, localhost a special hostname to use the local socket, but PostgreSQL will connect to a local socket only if host does not exist (not currently supported by pgsql driver). We are allowing socket connections for both MySQL and PostgreSQL on the test bots so it's not possible to test non-existent socket.
2. I can write a kernel test to test 08006 though by adding a connection info with a non-existent host.

I think that we should remove the handling in pgsql driver, and then change the exception class to by MySQL specific and specifically-named after localhost socket connecting.

Maybe a follow-up issue about handling connection errors better? Or if this issue is supposed to handle catching any connection refusal, than I think that the error message needs to be a bit more specific per driver as 10061 is a narrow use case and 08006 are better for handling general connection failure.

cameron tod’s picture

Title: Add informative error message for 'Connection refused' errors in MySQL and PostgreSQL » Add informative error message for 'Connection refused' errors in MySQL

I agree with the sentiment in #57. I think we should pull this issue back to just handling the MySQL issue, then maybe a follow up for the PostgreSQL, or perhaps a broader issue about handling connection errors better more generally.

awelch’s picture

Can I add I had this problem attempting to use drush using MAMP PRO, PHP 5.5.10.

GUI of site worked fine with just

$databases['default']['default'] = array (
  'database' => '****',
  'username' => '****',
  'password' => '****',
  'prefix' => '',
  'host' => 'localhost',
  'port'=>'3308',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

but drush threw:
exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in core/lib/Drupal/Core/Database/Driver/mysql/Connection.php:146

Changing to

$databases['default']['default'] = array (
  'database' => '****',
  'username' => '****',
  'password' => '****',
  'prefix' => '',
  'host' => '127.0.0.1',
  'port'=>'3308',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
  'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock'
);

Fixed it

as per
https://modulesunraveled.com/blog/drush-not-working-mamp-heres-how-fix-it

cilefen’s picture

Yes, see #2610858-23: Add informative error message for 'Connection refused' errors in MySQL. Drush is sending back exactly what the mysql client library reported.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

snlnz’s picture

MAMP PRO: 4.2 (9213)
PHP: 7.1.6
Drush: 8.0.5
Drupal: 8.2.1

#15 fixed the issue.

mradcliffe’s picture

I think there is consensus for #57, and this should offer some tasks for several contributors to rework the patch based on the comments in #57. First, update the issue summary to reflect the state of the issue. And a kernel or phpunit test could also be written for the new exception.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vacho’s picture

StatusFileSize
new3.36 KB

Patch rerolled. For this useful message.

asvira’s picture

Issue summary: View changes
Priority: Normal » Minor
Status: Needs work » Needs review
StatusFileSize
new4.26 KB

I updated issue summary and removed code related to pqsql and made exception class specific to MySQL.
Also, I customized error message depending on the reasons caused the issue.

Now error messages are:

1. The 'unix_socket' option is set in settings.php and the socket is not accessible.

Drupal\Core\Database\Driver\mysql\ConnectionRefusedException: SQLSTATE[HY000] [2002] No such file or directory [Tip: Drupal is configured to connect to the database server via a socket, but the socket file could not be found. This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.] in Drupal\Core\Database\Driver\mysql\Connection::open() (line 451 of /var/www/html/web/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php).

2. The 'host' option is empty or set to 'localhost', which means to use default Unix socket, but socket is not accessible.

Drupal\Core\Database\Driver\mysql\ConnectionRefusedException: SQLSTATE[HY000] [2002] No such file or directory [Tip: Drupal was attempting to connect to the database server via a socket, but the socket file could not be found. A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost. To connect via TPC/IP use IP address (127.0.0.1 for IPv4) instead of "localhost". This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.] in Drupal\Core\Database\Driver\mysql\Connection::open() (line 451 of /var/www/html/web/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php).

3. There is an issue with accessing the server via TCP/IP:

Drupal\Core\Database\Driver\mysql\ConnectionRefusedException: SQLSTATE[HY000] [2002] Connection refused [Tip: This message normally means that there is no MySQL server running on the system or that you are using an incorrect TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.] in Drupal\Core\Database\Driver\mysql\Connection::open() (line 451 of /var/www/html/web/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php).

Drupal\Core\Database\Driver\mysql\ConnectionRefusedException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve [Tip: This message normally means that there is no MySQL server running on the system or that you are using an incorrect TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.] in Drupal\Core\Database\Driver\mysql\Connection::open() (line 447 of /var/www/html/web/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php).

asvira’s picture

#1409108: Improve "Failed to connect to database" Error message (https://www.drupal.org/project/drupal/issues/1409108) might be considered as resolved in the scope of current issue and we could close it once the current patch is committed. It will show a tip about incorrect Unix socket during installation if the socket is used and connection failed with error code 2002.

This is an example of how it looks (text only, without markup):

Resolve all issues below to continue the installation. For help configuring your database server, see the installation handbook, or contact your hosting provider.
Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] No such file or directory [Tip: Drupal was attempting to connect to the database server via a socket, but the socket file could not be found. A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost. To connect via TPC/IP use IP address (127.0.0.1 for IPv4) instead of "localhost". This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.] .
Is the database server running?
Does the database exist or does the database user have sufficient privileges to create the database?
Have you entered the correct database name?
Have you entered the correct username and password?
Have you entered the correct database hostname and port number?

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Great improvement!

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

No longer applies

  1. +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
    @@ -420,6 +425,26 @@ public static function open(array &$connection_options = []) {
    +        elseif (isset($connection_options['host']) && in_array(strtolower($connection_options['host']), ['', 'localhost'], TRUE)) {
    ...
    +        else {
    

    nit: can we throw early here and avoid the elseif/else?

  2. +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
    @@ -420,6 +425,26 @@ public static function open(array &$connection_options = []) {
    +          $message .= ' To connect via TPC/IP use IP address (127.0.0.1 for IPv4) instead of "localhost".';
    

    nit Use *an* IP address

  3. +++ b/core/lib/Drupal/Core/Database/Driver/mysql/ConnectionRefusedException.php
    @@ -0,0 +1,10 @@
    +class ConnectionRefusedException extends DatabaseConnectionRefusedException {}
    

    this doesn't seem to be used?

daffie’s picture

Issue tags: +Needs reroll
ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.31 KB

Here is re-roll of patch #70

daffie’s picture

@ravi.shankar: Could you address the 3 points from @larowlan in comment #74?

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new3.68 KB

Here I have addressed point no. 2 and 3 of @larowlan comment #74. @daffie could you please suggest how can I address point 1 of comment #74? I don't think so if we can avoid those if else.

daffie’s picture

Status: Needs review » Needs work

@ravi.shankar: The changes you made for #74.2 and #74.3 are correct. And thank you for working on this!

The change that @larowlan wants for #74.1 is the following:

if ($e->getCode() == static::CONNECTION_REFUSED) {
  if (isset($connection_options['unix_socket'])) {
    // Show message for socket connection via 'unix_socket' option.
    $message = 'Drupal is configured to connect to the database server via a socket, but the socket file could not be found.';
    $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
    throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode(), $e);
  }
  if (isset($connection_options['host']) && in_array(strtolower($connection_options['host']), ['', 'localhost'], TRUE)) {
    // Show message for socket connection via 'host' option.
    $message = 'Drupal was attempting to connect to the database server via a socket, but the socket file could not be found.';
    $message .= ' A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost.';
    $message .= ' To connect via TPC/IP use an IP address (127.0.0.1 for IPv4) instead of "localhost".';
    $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
    throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode(), $e);
  }
  // Show message for TCP/IP connection.
  $message = 'This message normally means that there is no MySQL server running on the system or that you are using an incorrect host name or port number when trying to connect to the server.';
  $message .= ' You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.';
  throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode(), $e);
}

My suggestion is also to create a switch statement for the $e->getCode() equals part. I think this will make the part the most readable:

switch ($e->getCode()) {
  case static::CONNECTION_REFUSED:
    if (isset($connection_options['unix_socket'])) {
      // Show message for socket connection via 'unix_socket' option.
      $message = 'Drupal is configured to connect to the database server via a socket, but the socket file could not be found.';
      $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
      throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode(), $e);
    }
    if (isset($connection_options['host']) && in_array(strtolower($connection_options['host']), ['', 'localhost'], TRUE)) {
      // Show message for socket connection via 'host' option.
      $message = 'Drupal was attempting to connect to the database server via a socket, but the socket file could not be found.';
      $message .= ' A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost.';
      $message .= ' To connect via TPC/IP use an IP address (127.0.0.1 for IPv4) instead of "localhost".';
      $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
      throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode(), $e);
    }
    // Show message for TCP/IP connection.
    $message = 'This message normally means that there is no MySQL server running on the system or that you are using an incorrect host name or port number when trying to connect to the server.';
    $message .= ' You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.';
    throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode(), $e);
    break;
  case static::DATABASE_NOT_FOUND:
    throw new DatabaseNotFoundException($e->getMessage(), $e->getCode(), $e);
    break;
  case static::ACCESS_DENIED:
    throw new DatabaseNotFoundException($e->getMessage(), $e->getCode(), $e);
    break;
  default:
    throw $e;    
}
daffie’s picture

We also need to write some tests for the code that we add. My suggestion is to take Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::testLostDatabaseConnection() as an example. See: https://github.com/drupal/core/blob/8.8.x/tests/Drupal/FunctionalTests/B....

Madhura BK’s picture

Assigned: Unassigned » Madhura BK
Madhura BK’s picture

Have added the code as suggested in #79.

daffie’s picture

Almost there. 2 minor nitpicks left:

  1. +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
    @@ -416,13 +421,40 @@ public static function open(array &$connection_options = []) {
    +      ¶
    ...
    +          throw $e;  ¶
    

    Added spaces where their not supposed to be.

  2. +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
    @@ -416,13 +421,40 @@ public static function open(array &$connection_options = []) {
    +          // Show message for socket connection via 'host' option.
    

    This line is not correctly alligned.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.53 KB

@daffie Here I have made changes that mentioned in #83.

daffie’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
@@ -416,13 +421,39 @@ public static function open(array &$connection_options = []) {
+              // Show message for socket connection via 'unix_socket' option.
+              $message = 'Drupal is configured to connect to the database server via a socket, but the socket file could not be found.';
+              $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
+              throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode(), $e);

These 4 lines are inset too much.

Now we still need some tests. See comment #80.

Madhura BK’s picture

Assigned: Madhura BK » Unassigned
shubham.prakash’s picture

StatusFileSize
new4.02 KB

Fixed the indentation issue, still need tests.

shubham.prakash’s picture

StatusFileSize
new4.52 KB

Fixed the indentation issue, still need tests.

daffie’s picture

@shubham.prakash: Could you also post an interdiff.txt file. Such a file makes it easier for reviewers to see what you have changed in your new patch file. See: https://www.drupal.org/documentation/git/interdiff.

shubham.prakash’s picture

StatusFileSize
new2.02 KB

Forgot to provide interdiff, here it is.

daffie’s picture

Issue tags: -Needs issue summary update

@shubham.prakash: Thank you for fixing the indentation. Would you be interested in coding the tests. See comment #80.

@asvira did the IS update, so removing the tag

alvarito75’s picture

#21 worked for me.

chankongching’s picture

#21 worked for me too, with only adding
'unix_socket' => '/var/lib/mysql/mysql.sock',
and host is remain unchanged. i.e. localhost

ressa’s picture

The patch in #88 works fine with Drupal 9, providing more details, if the connections is refused. It does seem like the same message is shown twice ... Now I just need to figure out the reason for the error, but that's another issue :-)

Currently

$ php core/scripts/run-tests.sh Statistics
ERROR: mysql: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

With patch

$ php core/scripts/run-tests.sh Statistics
PHP Fatal error:  Uncaught PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/username/dev/d9dev/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php:155
Stack trace:
#0 /home/username/dev/d9dev/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(155): PDO->__construct('mysql:host=data...', 'drupal8', 'drupal8', Array)
#1 /home/username/dev/d9dev/core/lib/Drupal/Core/Database/Database.php(374): Drupal\Core\Database\Driver\mysql\Connection::open(Array)
#2 /home/username/dev/d9dev/core/lib/Drupal/Core/Database/Database.php(169): Drupal\Core\Database\Database::openConnection('test-runner', 'default')
#3 /home/username/dev/d9dev/core/scripts/run-tests.sh(663): Drupal\Core\Database\Database::getConnection('default', 'test-runner')
#4 /home/username/dev/d9dev/core/scripts/run-tests.sh(123): simpletest_script_setup_database(true)
#5 {main}

Next PDOException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/username/dev/d9dev/core/lib/Drupa in /home/username/dev/d9dev/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php on line 177

(removed the duplicate error message)

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

sharma.amitt16’s picture

Assigned: Unassigned » sharma.amitt16
sharma.amitt16’s picture

Assigned: sharma.amitt16 » Unassigned
sharma.amitt16’s picture

Status: Needs work » Needs review

Patch #88 looks good to me. I have applied the patch to D9.1.x

Before patch applies I got below error message.

The website encountered an unexpected error. Please try again later.
PDOException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known in Drupal\Component\DependencyInjection\PhpArrayContainer->createService() (line 79 of /var/www/html/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php).
Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'database') (Line: 171)
Drupal\Component\DependencyInjection\Container->get('database', 1) (Line: 212)
Drupal\Component\DependencyInjection\PhpArrayContainer->resolveServicesAndParameters(Array) (Line: 62)
Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'cache.container') (Line: 171)
Drupal\Component\DependencyInjection\Container->get('cache.container') (Line: 546)
Drupal\Core\DrupalKernel->getCachedContainerDefinition() (Line: 891)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 470)
Drupal\Core\DrupalKernel->boot() (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

After patch apply I got below

The website encountered an unexpected error. Please try again later.
Drupal\Core\Database\DatabaseConnectionRefusedException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known [Tip: This message normally means that there is no MySQL server running on the system or that you are using an incorrect host name or port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.] in Drupal\Core\Database\Driver\mysql\Connection::open() (line 162 of /var/www/html/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php).
Drupal\Core\Database\Driver\mysql\Connection::open(Array) (Line: 380)
Drupal\Core\Database\Database::openConnection('default', 'default') (Line: 169)
Drupal\Core\Database\Database::getConnection('default')
call_user_func_array('Drupal\Core\Database\Database::getConnection', Array) (Line: 79)
Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'database') (Line: 171)
Drupal\Component\DependencyInjection\Container->get('database', 1) (Line: 212)
Drupal\Component\DependencyInjection\PhpArrayContainer->resolveServicesAndParameters(Array) (Line: 62)
Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'cache.container') (Line: 171)
Drupal\Component\DependencyInjection\Container->get('cache.container') (Line: 546)
Drupal\Core\DrupalKernel->getCachedContainerDefinition() (Line: 891)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 470)
Drupal\Core\DrupalKernel->boot() (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

It looks good to have more information about the database connection error.

Thanks for the patch

daffie’s picture

Status: Needs review » Needs work

The patch still automatic tests.

daffie’s picture

Issue tags: +Bug Smash Initiative
anybody’s picture

Just ran into this problem and think this is still relevant. For normal users it's hard to understand what happened, for example if the database can not be connected.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new9.22 KB
new5.95 KB

- Add the test cases to validate errors.
- Re-roll the patch, as patch wasn't applicable to 9.2.x

kapilv’s picture

StatusFileSize
new5.95 KB
renatog’s picture

Status: Needs review » Needs work
/**
  * Error code for "Connection refused" error.
  */
  const CONNECTION_REFUSED = 2002;

On this case the expression is redudant
Error code for "Connection refused" error.

We can use it:

/**
  * Error code for "Connection refused".
  */
  const CONNECTION_REFUSED = 2002;

It's easier and clear

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new9.21 KB
new536 bytes

Addressed comment #105.

tyler36’s picture

Is there a valid reason why the patch $message text is not translatable?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new147 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

joachim’s picture

Status: Needs work » Needs review

Made a MR on 10.1.

andypost’s picture

grevil’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new15.59 KB
new10.91 KB
new10.63 KB

LGTM!

The patch applies successfully to 10.1.x and works as expected!

Message for invalid "localhost" or empty host option:
screenshot1

Message for incorrect "unix_socket" entry:
screenshot2

Message for general invalid host option:
screenshot3

RTBC!

grevil’s picture

Although, I am unsure about the unix socket mentioning inside the first screenshot, for the "if (isset($connection_options['host']) && in_array(strtolower($connection_options['host']), ['', 'localhost'], TRUE))"
Case. Maybe someone with more insight could have a look.

Edit: Note to me, I should read the message properly first...

larowlan’s picture

Adding issue credits

  • larowlan committed 9a625bf8 on 10.0.x
    Issue #2610858 by cilefen, ravi.shankar, Cameron Tod, shubham.prakash,...

  • larowlan committed 442c0e41 on 10.1.x
    Issue #2610858 by cilefen, ravi.shankar, Cameron Tod, shubham.prakash,...
larowlan’s picture

Title: Add informative error message for 'Connection refused' errors in MySQL » [Needs backport] Add informative error message for 'Connection refused' errors in MySQL
Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to 10.1.x and 10.0.x, it doesn't apply cleanly to 9.5.x so marking for backport.

Thanks folks

ravi.shankar’s picture

StatusFileSize
new9.16 KB
new3.06 KB

Added a patch for Drupal 9.5.x, and also added reroll diff between MR and the new patch, please review.

catch’s picture

Version: 9.5.x-dev » 10.0.x-dev
Status: Patch (to be ported) » Fixed

There's a fair amount going on here and we're approaching the final bugfix release for 9.5.x, so I think we should leave this fixed in 10.0.x.

anybody’s picture

Title: [Needs backport] Add informative error message for 'Connection refused' errors in MySQL » Add informative error message for 'Connection refused' errors in MySQL

Thanks @catch!
Removing "[Needs backport]" from the title so.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.