Error: Class "Drupal\Driver\Database\mysql\Connection" not found

Created on 17 January 2023, over 1 year ago
Updated 11 April 2024, 2 months ago

I was updating the site from Drupal 8.9.20 to Drupal 9.5.1 in my local environment.

After updating moved the files and database to the test server and received an error:

The website encountered an unexpected error. Please try again later.
Error: Class "Drupal\Driver\Database\mysql\Connection" not found in Drupal\Core\Database\Database::openConnection() (line 463 of /var/www/html/core/lib/Drupal/Core/Database/Database.php).

Drupal\Core\Database\Database::openConnection() (Line: 188)
Drupal\Core\Database\Database::getConnection()
call_user_func_array() (Line: 79)
Drupal\Component\DependencyInjection\PhpArrayContainer->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 212)
Drupal\Component\DependencyInjection\PhpArrayContainer->resolveServicesAndParameters() (Line: 62)
Drupal\Component\DependencyInjection\PhpArrayContainer->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 560)
Drupal\Core\DrupalKernel->getCachedContainerDefinition() (Line: 937)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 482)
Drupal\Core\DrupalKernel->boot() (Line: 711)
Drupal\Core\DrupalKernel->handle() (Line: 19)

I can't figure out what is going on, the site is working fine in the local Lando (Drupal 8 recipe) environment.

My server is running Ubuntu 20.04 LTS, MariaDB 10.3.37, nginx, php8.1-fpm

What are the steps required to reproduce the bug?
For me, it was moving the site from the local environment to the testing server, but I know that it would be hard to reproduce this current situation.

What behavior were you expecting?
The site should open without fatal errors.

What happened instead?
The site is not opening, the error is
Error: Class "Drupal\Driver\Database\mysql\Connection" not found in Drupal\Core\Database\Database::openConnection() (line 463 of /var/www/html/core/lib/Drupal/Core/Database/Database.php).

💬 Support request
Status

Fixed

Version

10.2

Component
Database 

Last updated about 17 hours ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇬🇪Georgia almador

Live updates comments and jobs are added and updated live.
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.

  • Status changed to Postponed: needs info over 1 year ago
  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed about 1 year ago
  • I have encountered exactly the same error today when upgrading from 8.9.20 to 9.5.9. All packages were successfully updated by composer. I updated settings.php from the new default.settings.php, and when I ran "drush updb", it failed. I updated drush, thinking it could be the reason, but the error persisted.

    We are on My SQL 5.7.23-23 and PHP 8.1.18 (updated before running composer to update core-recommended).

    This is the full drush -vvv error:

    [preflight] Config paths: /drupal-root-dir/vendor/drush/drush/drush.yml
    [preflight] Alias paths: /drupal-root-dir/web/drush/sites,/drupal-root-dir/drush/sites
    [preflight] Commandfile search paths: /drupal-root-dir/vendor/drush/drush/src
    [info] Starting bootstrap to full [0.28 sec, 8.1 MB]
    [info] Drush bootstrap phase 5 [0.28 sec, 8.16 MB]
    [info] Try to validate bootstrap phase 5 [0.28 sec, 8.16 MB]
    [info] Try to validate bootstrap phase 5 [0.28 sec, 8.16 MB]
    [info] Try to bootstrap at phase 5 [0.28 sec, 8.16 MB]
    [info] Drush bootstrap phase: bootstrapDrupalRoot() [0.28 sec, 8.16 MB]
    [info] Change working directory to /drupal-root-dir/web [0.28 sec, 8.16 MB]
    [info] Initialized Drupal 9.5.9 root directory at /drupal-root-dir/web [0.28 sec, 8.16 MB]
    [info] Try to validate bootstrap phase 5 [0.28 sec, 8.16 MB]
    [info] Try to bootstrap at phase 5 [0.28 sec, 8.17 MB]
    [info] Drush bootstrap phase: bootstrapDrupalSite() [0.28 sec, 8.17 MB]
    [debug] Could not find a Drush config file at sites/default/drush.yml. [0.28 sec, 8.34 MB]
    [info] Initialized Drupal site default at sites/default [0.28 sec, 8.34 MB]
    [info] Try to validate bootstrap phase 5 [0.28 sec, 8.34 MB]
    [info] Try to bootstrap at phase 5 [0.28 sec, 8.34 MB]
    [info] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.28 sec, 8.34 MB]
    [debug] Add service modifier [0.29 sec, 8.57 MB]
    [info] Try to validate bootstrap phase 5 [0.29 sec, 8.57 MB]
    Error: Class "Drupal\mysql\Driver\Database\mysql\Connection" not found in Drupal\Core\Database\Database::openConnection() (line 463 of /drupal-root-dir/vendor/drupal/core/lib/Drupal/Core/Database/Database.php).
    [warning] Drush command terminated abnormally. [0.31 sec, 8.9 MB]

    I have tried commenting and uncommenting the 'namespace' entry in settings.php as suggested above but it doesn't make any difference.

  • 🇬🇪Georgia almador

    drupalsilm
    Did you check in the modules list if the 'mysql' module is installed?

  • Hi almador, thank you for your quick response.

    That seems to be the problem, mysql is not listed in the key_values database table, and I guess it should be. I couldn't check any other way as drush doesn't work at all.

    Can mysql be enabled without drush and without access to the admin UI?

  • 🇬🇪Georgia almador

    drupalsilm, could you please provide the output of CLI when you are trying to run drush?

    Also, it seems that you have direct access to the database. You could try from here:

    • - Manually edit the config table where name = 'core.extension' and remove the module from the data blob which is a serialized array.
    • - Be aware to decrement the module array length as well (...s:6:"module";a:HERE;{...)
    • - Truncate the cache_config table from phpmyadmin or using command-line.

    https://drupal.stackexchange.com/questions/72927/manually-disable-a-module

  • Almador, when you say the output of CLI, what command do you mean?

    Yes, I have access to the database but I'm unable to follow the instructions you provided as there's nothing to delete... mysql is NOT listed inside the blob, in either version (8.9.20 or 9.5.9) of the site database.

  • 🇬🇪Georgia almador

    drupalsilm, 'drush updb' for example

  • When I run "drush updb":

    Error: Class "Drupal\mysql\Driver\Database\mysql\Connection" not found in Drupal\Core\Database\Database::openConnection() (line 463 of /drupal-project-dir/vendor/drupal/core/lib/Drupal/Core/Database/Database.php).
    [warning] Drush command terminated abnormally.

    With -vvv, this is the output:

    Box Requirements Checker
    ========================

    > Using PHP 8.1.18
    > PHP is using the following php.ini file:
    /opt/cpanel/ea-php81/root/etc/php.ini

    > Checking Box requirements:
    ✔ The package "composer/xdebug-handler" requires the version "^5.3.2 || ^7.0 || ^8.0" or greater.
    ✔ The package "laravel-zero/phar-updater" requires the version "^7.3|^8.0" or greater.
    ✔ The package "psr/log" requires the version ">=5.3.0" or greater.
    ✔ The package "webmozart/assert" requires the version "^7.2 || ^8.0" or greater.
    ✔ The package "webmozart/path-util" requires the version ">=5.3.3" or greater.
    ✔ The package "webflo/drupal-finder" requires the extension "json".
    ✔ The package "webmozart/assert" requires the extension "ctype".

    [OK] Your system is ready to run the application.

    [preflight] Config paths: /drupal-project-dir/vendor/drush/drush/drush.yml
    [preflight] Alias paths: /drupal-project-dir/web/drush/sites,/drupal-project-dir/drush/sites
    [preflight] Commandfile search paths: /drupal-project-dir/vendor/drush/drush/src
    [info] Starting bootstrap to full [0.31 sec, 9.5 MB]
    [info] Drush bootstrap phase 5 [0.31 sec, 9.5 MB]
    [info] Try to validate bootstrap phase 5 [0.31 sec, 9.5 MB]
    [info] Try to validate bootstrap phase 5 [0.31 sec, 9.5 MB]
    [info] Try to bootstrap at phase 5 [0.31 sec, 9.5 MB]
    [info] Drush bootstrap phase: bootstrapDrupalRoot() [0.31 sec, 9.5 MB]
    [info] Change working directory to /drupal-project-dir/web [0.31 sec, 9.5 MB]
    [info] Initialized Drupal 9.5.9 root directory at /drupal-project-dir/web [0.31 sec, 9.5 MB]
    [info] Try to validate bootstrap phase 5 [0.31 sec, 9.5 MB]
    [info] Try to bootstrap at phase 5 [0.31 sec, 9.51 MB]
    [info] Drush bootstrap phase: bootstrapDrupalSite() [0.31 sec, 9.51 MB]
    [debug] Could not find a Drush config file at sites/default/drush.yml. [0.32 sec, 9.68 MB]
    [info] Initialized Drupal site default at sites/default [0.32 sec, 9.68 MB]
    [info] Try to validate bootstrap phase 5 [0.32 sec, 9.68 MB]
    [info] Try to bootstrap at phase 5 [0.32 sec, 9.68 MB]
    [info] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.32 sec, 9.68 MB]
    [debug] Add service modifier [0.33 sec, 9.97 MB]
    [info] Try to validate bootstrap phase 5 [0.33 sec, 9.97 MB]
    Error: Class "Drupal\mysql\Driver\Database\mysql\Connection" not found in Drupal\Core\Database\Database::openConnection() (line 463 of /drupal-project-dir/vendor/drupal/core/lib/Drupal/Core/Database/Database.php).
    [warning] Drush command terminated abnormally. [0.35 sec, 9.92 MB]

    Is this what you meant?

  • 🇬🇪Georgia almador

    I suggest you've already tried removing:
    'namespace' => 'Drupal\Driver\Database\mysql',
    from settings.php

    I can't remember how it was fixed in my situation, but you could try to:

    - rename drupal 'web/core' folder to 'web/core2'
    - rename 'vendor' folder to 'vendor2'
    - rename 'composer.lock' to 'composer_old.lock'
    - run 'composer install'
    - run 'drush cr' and 'drush updb'

    Make sure you've created the code and database backup before doing this!

  • I followed the instructions you gave me, did a full composer install that was completed without a glitch. Still drush fails to work when running "drush updb" but the error now has changed to something else. Hopefully it will give a better clue:

    [preflight] Config paths: /drupal-project-root/vendor/drush/drush/drush.yml
    [preflight] Alias paths: /drupal-project-root/web/drush/sites,/drupal-project-root/drush/sites
    [preflight] Commandfile search paths: /drupal-project-root/vendor/drush/drush/src
    [info] Starting bootstrap to full [0.24 sec, 8.11 MB]

    In BootstrapHook.php line 36:

    [Exception]
    Bootstrap failed. Run your command with -vvv for more information.

    Exception trace:
    at /drupal-project-root/vendor/drush/drush/src/Boot/BootstrapHook.php:36
    Drush\Boot\BootstrapHook->initialize() at /drupal-project-root/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:44
    Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->doInitializeHook() at /drupal-project-root/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:36
    Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook() at /drupal-project-root/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:29
    Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize() at /drupal-project-root/vendor/consolidation/annotated-command/src/CommandProcessor.php:145
    Consolidation\AnnotatedCommand\CommandProcessor->initializeHook() at /drupal-project-root/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:375
    Consolidation\AnnotatedCommand\AnnotatedCommand->initialize() at /drupal-project-root/vendor/symfony/console/Command/Command.php:221
    Symfony\Component\Console\Command\Command->run() at /drupal-project-root/vendor/symfony/console/Application.php:1039
    Symfony\Component\Console\Application->doRunCommand() at /drupal-project-root/vendor/symfony/console/Application.php:275
    Symfony\Component\Console\Application->doRun() at /drupal-project-root/vendor/symfony/console/Application.php:149
    Symfony\Component\Console\Application->run() at /drupal-project-root/vendor/drush/drush/src/Runtime/Runtime.php:124
    Drush\Runtime\Runtime->doRun() at /drupal-project-root/vendor/drush/drush/src/Runtime/Runtime.php:51
    Drush\Runtime\Runtime->run() at /drupal-project-root/vendor/drush/drush/drush.php:77
    require() at /drupal-project-root/vendor/drush/drush/drush:4
    include() at /drupal-project-root/vendor/bin/drush:120

    This is the database definition in settings.php:

    $databases['default']['default'] = array (
    'database' => 'db_name',
    'username' => 'db_user',
    'password' => 'db_password',
    'host' => 'localhost',
    'port' => '3306',
    'driver' => 'mysql',
    'prefix' => '',
    'collation' => 'utf8mb4_general_ci',
    );

  • I fixed the issue.

    I replaced the composer.json file (D8 version) with the one downloaded from github for recommended-project (version 9.5.9). I didn't change anything except to add the lines for modules installed my site. Then I re-ran composer install. This time, when I re-ran drush updb, it worked.

    Thank you, almador, for your suggestions. It was the re-install idea that made me start from scratch there too.

  • 🇱🇹Lithuania vibrasphere

    Happened same with Drupal 10.

    Built the website on local Windows 10 and uploaded it to Ubuntu.

    For some reason settings.php formatting was like this:

    'autoload' => 'core/modules/mysql\\src\\Driver\\Database\\mysql\\',

    And if you replace it with this, the issue is solved:
    'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',

  • 🇦🇹Austria dawitti

    I faced the same issue after migrating a site to a new server and simply copying all files.

    As @almador said in #19, deleting vendor, composer.lock and the web/core directory, and the restoring it via composer install fixed the issue for me.

    Make a backup before deleting things.

Production build 0.69.0 2024