---
title: "How do I override the default MySQL wait_timeout setting?"
date: "2025-02-06T01:30:17+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/help/92266-how-do-i-override-default-mysql-waittimeout-setting"
id: "ef39d53f-2fbc-45a2-a27a-9e1d865b88c6"
---

Table of contents will be added

Issue
-----

Sometimes, you might have the requirement to override MySQL's default setting for `**wait_timeout**` on [Acquia Cloud](/node/55808) or [Site Factory](/node/55800). One possible situation is that 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..]

On Acquia Cloud, changing the MySQL timeout can't be done on the MySQL server (as it is a platform-wide setting). However, individual Drupal applications _can_ override that setting on a 'per session' basis, i.e. for every PHP process that bootstraps Drupal and connects to the database.

The way to do this is to add some code in your `**settings.php**` file (for Acquia Cloud users), or in your [**pre and post** settings hooks](/node/57269) for Acquia Cloud Site Factory. 

Caution

*   Below snippets are examples, and may not match what your resulting 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.
*   Ensure you're not calling `**require('/var/www/site-php/...')**` several times in your code; you must call it only once, ensuring you've placed any additional lines before/after that statement.
*   The examples below use a value of `1200` seconds (20 minutes); some **long drush operations** like data imports, rebuilding of Site Studio components, etc, **may need larger timeout values**.

Resolution
----------

### Acquia Cloud without BLT

The following recommendations are for both [Acquia Cloud Platform](/node/55808) infrastructure and [Acquia Cloud Classic](/node/55808) infrastructure environments which do not use [Acquia BLT](/node/55931) in their code base.

The _recommended additions_ to `settings.php` start with a + sign:

     if (file_exists('/var/www/site-php')) {
    +   global $conf, $databases;   $conf['acquia_hosting_settings_autoconnect'] = FALSE;
       // Use your existing 'require' statement here
       require('/var/www/site-php/XXXXXX/XXXXX-settings.inc');
      
    +   // For Cloud Platform you also need to raise interactive_timeout
    +   // See https://ahmedahamid.com/amazon-aurora-mysql-and-wait-timeout/
    +   $databases['default']['default']['init_commands'] = array(
    +     'wait_timeout' => 'SET SESSION wait_timeout=1200',
    +     'interactive_timeout' => 'SET SESSION interactive_timeout=1200',
    +   );
    +  if (function_exists('acquia_hosting_db_choose_active')){
    +     acquia_hosting_db_choose_active(
    +       $conf['acquia_hosting_site_info']['db'],
    +       'default',
    +       $databases,
    +       $conf
    +     );
    +   }
     }

### Acquia Cloud using BLT

The following recommendations are for both [Acquia Cloud Platform](/node/55808) infrastructure and [Acquia Cloud Classic](/node/55808) infrastructure environments that use [Acquia BLT](/node/55931) in their code base.

If you are using [BLT](/node/55931), look for your existing `**require...blt.settings.php**` statement and add the lines that start with a + sign around it.

     if (file_exists('/var/www/site-php')) {
    +  global $conf, $databases;
    +  $conf['acquia_hosting_settings_autoconnect'] = FALSE;
    
      // Use your existing 'require' statement here 
      require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";
    
    +  $databases['default']['default']['init_commands'] = array( 
    +    'wait_timeout' => 'SET SESSION wait_timeout=1200',
    +    'interactive_timeout' => 'SET SESSION interactive_timeout=1200',
    +  );
    +  if (function_exists('acquia_hosting_db_choose_active')){
    +    acquia_hosting_db_choose_active(
    +      $conf['acquia_hosting_site_info']['db'],
    +      'default',
    +      $databases,
    +      $conf
    +    );
    +  }
     }

### Site Factory users

For Site Factory users the above snippet needs to be split in two. The first snippet should be placed in your [pre-settings-php hook](/node/57269), and the latter on your [post-settings-php hook](/node/57269):

**pre-settings-php**

    global $conf, $databases;
    $conf['acquia_hosting_settings_autoconnect'] = FALSE;

    post-settings-php

    $databases['default']['default']['init_commands'] = array(
      'wait_timeout' => "SET SESSION wait_timeout=1200",
      'interactive_timeout' => "SET SESSION interactive_timeout=1200",
    );
    acquia_hosting_db_choose_active();

Checking the current MySQL variables
------------------------------------

Once you have the appropriate snippet in your code base, you can confirm that the overrides are working for your application by running the following `drush eval` command below. You can use this command as a starting point and modify it as needed for your application's purposes.

 The command outputs the MySQL variables through the Drupal database connection being used in settings.php, for Acquia Cloud or [pre-settings-php hook](/node/57269), and [post-settings-php hook](/node/57269), for Site Factory.

**Note**

You might not see the override values with a `**drush sql-cli**` session, which is why the [Drupal\\Core\\Database\\Database::getConnection](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21Database.php/function/Database%3A%3AgetConnection/11.x) function is being used.

    # Edit the Site URL
    # Remove the last |egrep... section to see all variables. 
    drush --uri=[Site-URL] eval '$x = (array)Drupal\Core\Database\Database::getConnection("default", "default")->query("SHOW VARIABLES;")->fetchAll(); foreach ($x as $v) { echo $v->Variable_name . " => " . $v->Value . PHP_EOL; }' |egrep '^(wait|interactive)_timeout'

This should show the values you've overridden above.

An example output:

    interactive_timeout => 1200wait_timeout => 1200