Add informative error message for 'Connection refused' errors in MySQL

Created on 7 November 2015, over 8 years ago
Updated 26 May 2023, about 1 year ago

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.

πŸ› Bug report
Status

Fixed

Version

10.0 ✨

Component
DatabaseΒ  β†’

Last updated 37 minutes ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡ΊπŸ‡ΈUnited States rgracia

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024