简体   繁体   中英

Drupal: PDOException: SQLSTATE[HY000] [2002] Connection refused in lock_may_be_available()

I tried installing Drupal on my local server, and everything worked fine. I installed Drupal on my localhost, and then I tried to transfer the same Drupal directory on my server using FileZilla. Changed my settings.php file in accordance to my server MySql settings as follows:

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'manas_drupal',
      'username' => 'XXXXXXX',
      'password' => 'XXXXXXX',
      'host' => '127.0.0.1',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

However, when I tried accessing the website where the Drupal installation should have been present, I encounter the following error:

PDOException: SQLSTATE[HY000] [2002] Connection refused in lock_may_be_available() (line 167 of /home/manasge/manas.getevangelized.com/drupal/includes/lock.inc).

Now, line 167 of lock.inc contains the following function:

function lock_may_be_available($name) {
  $lock = db_query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc();
  if (!$lock) {
    return TRUE;
  }
  $expire = (float) $lock['expire'];
  $now = microtime(TRUE);
  if ($now > $expire) {
    // We check two conditions to prevent a race condition where another
    // request acquired the lock and set a new expire time. We add a small
    // number to $expire to avoid errors with float to string conversion.
    return (bool) db_delete('semaphore')
      ->condition('name', $name)
      ->condition('value', $lock['value'])
      ->condition('expire', 0.0001 + $expire, '<=')
      ->execute();
  }
  return FALSE;
}

What seems to be wrong here? Everything works fine on my localhost, but I can't seem to get this thing working on my main host. For reference, this is the link where my Drupal directory is hosted: http://manas.getevangelized.com/drupal/

Also, I have an empty database named manas_drupal defined in PHPMyAdmin already. Also, I made sure that the username and password for MySQL in settings.php were entered correctly.

Check MySQL is running correctly.

This happened to me because the server that was running MySQL had killed off the process, although the specifics of why this happened are not relevant. When my instance of drupal went to connect to the database it was given 'Connection Refused'.

I then attempted to directly connect to the database but I had similar issues connecting. A thread I found here suggested restarting MySQL. When I checked the status of MySQL it gave me the following error:

$ sudo service mysql status

MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]

After restarting it, my drupal instance worked as normal again.

您的数据库不应为空,请从localhost导出数据库,然后将其导入在线服务器中的空数据库中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM