How to configure mysql database connection with a different socket I have a Drupal 6 site that I ran for years before walking away about three years ago. I would like to resurrect the site in a more modern CMS and am first considering Drupal 8.

I run my site on a shared server where I have my own mysql socket. In Drupal 6, I connected to the database successfully in settings.php through the following syntax:

ini_set('mysqli.default_socket', '/path/to/my/mysql/socket');
ini_set('mysql.default_socket', '/path/to/my/mysql/socket');
$db_url = 'mysqli://dbuser:dbpass@localhost/dbname';


Looking at Drupal 8's settings.php it's a completely different syntax, and I am stumped on how to configure it correctly either there or on the Database configuration screen during install.php. Googling things like "drupal 8 mysql socket" brings up old articles that aren't relevant anymore.

PHP 7.0 is provided and I don't have write access to the ini, so I can't override the socket there.

I have confirmed that the database is running with this command:

mysqladmin --socket=/path/to/my/mysql/socket --user=dbuser -p status


Any help would be greatly appreciated on how to get the database setup in Drupal 8, thank you.

Edit: from Clive's suggestion I added the ini_set() lines above to Drupal 8's settings.php to no avail. I'm assuming it's user error at this point so I'm still trying things.
According to this Drupal issue, setting the socket in the UI is just not possible right now: (at least in 8.6.10)

https://www.drupal.org/project/drupal/issues/793200

I also could not figure out how to set the socket in sites/default/settings.php.

I had to resort to hardcoding my socket in this file:

core/lib/Drupal/Core/Database/Driver/mysql/Connection.php


This block of code:

    // The DSN should use either a socket or a host/port.
    if (isset($connection_options['unix_socket'])) {
      $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']);
    }


I could not find any way to set "unix_socket" value on $connection_options, so I resorted to hardcoding it before this block like:

$connection_options['unix_socket'] = '/path/to/my/mysql/socket';