Sometimes you might have the requirement to override MySQL's default setting for wait_timeout
on Acquia Cloud Platform or Acquia Cloud Site Factory.
One possible situation, is your logs may be showing messages like these:
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in [..snip..]/core/lib/Drupal/Core/Database/[..snip..]
While implementing an override cannot be done on the MySQL server configuration, directly, as this level of configuration is centrally managed, you can override that setting on a 'per session' basis, i.e. for every PHP process that bootstraps Drupal.
In the code snippets below, the following names are used to represent specifics for your application:
MYSITE
is your docrootSITE
is your site URL or the mulitsite nameVARIABLE_NAME
is the MySQL variable nameThe following provides details for configuring the MySQL wait_timeout
value, depending upon your application installation configuration.
Do take these precautions:
settings.php
will look like. You should look for your existing require('/var/www/site-php/...')
line and then add the extra suggested lines around it.require('/var/www/site-php/...')
several times in your code; you must call it only once, ensuring you've placed any additional lines before or after that statement.1200
seconds (20 minutes); some long drush operations like data imports, rebuilding of Site Studio components, etc, may need larger timeout values.If you are not using Acquia BLT, you can follow the steps in the Overriding Drupal $databases settings page, but replace the following code snippet in the settings.php
:
$databases['default']['default']['init_commands'] = array(
'VARIABLE_NAME_1' => 'SET SESSION VARIABLE_NAME_1=VALUE_1',
'VARIABLE_NAME_2' => 'SET SESSION VARIABLE_NAME_2=VALUE_2',
);
with this code snippet:
$databases['default']['default']['init_commands'] = [
'wait_timeout' => 'SET SESSION wait_timeout=<value>'
];
#Example using a value 0f 1200
$databases['default']['default']['init_commands'] = [
'wait_timeout' => 'SET SESSION wait_timeout=1200'
];
You can verify the MySQL transaction setting using the following Drush
command:
Drush
command:drush eval 'print_r(Drupal\Core\Database\Database::getConnection("default", "default")->query("SHOW VARIABLES LIKE '\'wait_timeout\'';")->fetchObject());'
drush eval 'print_r(Drupal\Core\Database\Database::getConnection("default", "default")->query("SHOW VARIABLES LIKE '\'transaction_isolation\'';")->fetchObject());'
stdClass Object
(
[Variable_name] => wait_timeout
[Value] => 1200
)
If this content did not answer your questions, try searching or contacting our support team for further assistance.
Wed Jan 22 2025 12:51:14 GMT+0000 (Coordinated Universal Time)