I am using Drupal 7 with MySQL 5.5 for my client website. Often I get the below error and site is not working.

PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in lock_may_be_available() (line 167 of D:\xxxinetpub\xxxwwwroot\live\xxxincludes\lock.inc).

Can someone help please?

Thanks in advance

Comments

sprite’s picture

That isn't likely a Drupal problem.

That is a MySQL settings/configuration problem.

Read the MySQL documentation about changing the:

my.ini

file.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

logus’s picture

Thanks. It was MySQL problem. It is fixed now as I restarted MySQL and worked fine

5418ryadav’s picture

@Logus, Kindly let me know, How did solve this issue?

logus’s picture

We checked our mysql connection and restarted the MySQL server.  Make sure no error during the restart. Then site worked fine.

laboratory.mike’s picture

I just ran into the same issue. For us, we had a separate web server and DB server, and we needed to set the bind-address in my.cnf under [mysqld] . The DB was working fine after that.

jaisy’s picture

As a quick fix you can drop semaphore table from your drupal database and create it again, because this problem is related to semaphore table. For creating the table you can use the following code.

CREATE TABLE `semaphore` (
  `name` varchar(255) NOT NULL DEFAULT ''COMMENT
) ;
 

This worked for me.For more reading please refer here.

msnandarhtay’s picture

i first use drupal 7.58 and xampp 1.7.4.Then i upgrade xampp 3.2.2 and drupal  7.64. i gained a lot of error and finally

PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in lock_may_be_available() (line 167 of C:\xampp\htdocs\MyProject\includes\lock.inc).

please let me know where to put your code.

mmjvb’s picture

3.2.2 is the version of the Control Panel in Xampp, which can be used in several versions of Xampp.

The commands mentioned above are SQL commands, to be used in the Database management tools provided in Xampp. You should have the normal command line utilities and the web interface: phpMyAdmin. Which is available from the Control Panel. Use the SQL tab in phpMyadmin, paste the command in there and have it executed.

Suggest either 5.6 or 7.1 version of Xampp.

lakshmi_a’s picture

if you are facing below issue please check your mysql PORT's

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

if you are using mysql 8 version then use PORT : 3308.

go to setting.php

$databases['default']['default'] = array ('database' => 'meme_v3',

'username' => 'root',

 'password' => '',

  'prefix' => '',

  'host' => 'localhost',

  'port' => '3308',

  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',

  'driver' => 'mysql',

);

other wise user PORT: 3306

my self issue is resolved.

Thanks

wasid’s picture

Thanks a lot. The solution worked for me perfectly. But still could not identify why this happened in a running Vhost after just changing the db name for testing purpose :(

Partha Sarathi’s picture

Thanks @lakshmi_a

You have just saved my day.

prabhakarb’s picture

Making 'port' => '' is resolved my problem

paulwings’s picture

This error is a network-related error occurred while establishing a connection to the Server. It means that the error is occurring because there is no server listening at the hostname and port you assigned. It happens that something is preventing a connection to the port or hostname. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that specific port. This may be because it is not running at all or because it is listening on a different port.