Could not connect: No connection could be made because the target machine actively refused them

Asked

Viewed 24,505 times

0

I am trying to connect to my database. This is easyphp webserver 14.1.

MYSQL

inserir a descrição da imagem aqui

Follow php code for connection.

<?php 

$HOST = '10.40.0.185:3388';
$USER= '*****'; // Aqui informei o usuário do meu banco
$PASS= '*****'; // Aqui informaei a senha do usuário para acesso ao banco
$BANCO = 'gclient_embratel';

$conexao = mysql_connect($HOST,$USER,$PASS) or die('Não foi possivel conectar: '.mysql_error());

$selecao = mysql_select_db($BANCO);?>

Follow the error message: inserir a descrição da imagem aqui

  • There may be several possibilities: 1 - The database server is not started on the machine (most likely), 2 - A firewall may be blocking access to the Mysql port.

1 answer

1

Answer:

As you are using the database on the same machine of the application the connection configuration to the database can be changed to:

<?php 

    $HOST = 'localhost:3388';
    $USER= '*****';
    $PASS= '*****';
    $BANCO = 'gclient_embratel';

    $conexao = mysql_connect($HOST,$USER,$PASS) or die('Não foi possivel conectar: '.mysql_error());

    $selecao = mysql_select_db($BANCO);?

?>

In place of the IP of your external machine defined in the variable $HOST put the value localhost, but could also be used 127.0.0.1.

How much the refused connection can occur for several factors, being the main ones:

  1. Mysql database service was not started and is not running on port 3388. If you use Linux you can do the command fuser 3388/tcp to check if there is a process using this port.

  2. Is there a restriction on your machine’s firewall to port 3388.

  3. You are using a machine from Amazon Web Services for your application? It is necessary to release the port in the security settings of your instance.

Putting the value localhost in the variable $HOST probably the options 2 and 3 are discarded because local machine port 3388 will be accessed without external access.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.