Mysql error 2002 connection refused

Asked

Viewed 1,207 times

1

I hosted a website on 007gb.with and I’m trying to access my remote database but I get the message

"Mensagem do erro: SQLSTATE[HY000] [2002] Connection refused
Code: 2002
Fatal error: Call to a member function prepare() on string in /srv/disk13/2292110/www/pirataswe0.medianewsonline.com/test.php on line 14"

What could it be? i created a script in php for ease:

<?php

function connectdb() {
    try {
        $return = new PDO("mysql:host=179.213.XX.XX;port=3306,dbname=pwdb;charset=utf8", 'root', '***********',[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
    } catch (PDOException $exc) {
      echo  $return = 'Mensagem do erro: ' . $exc->getMessage().
         '<br>Code: ' . $exc->getCode();
    }
    return $return;
}

$db = connectdb();
$select = $db->prepare("SELECT title FROM posts");
$select->execute();
echo $select->rowCount().'</br>';
while ($data = $select->fetch(PDO::FETCH_ASSOC)) {
    echo $data['title'].'</br>';
}

The port is the same default, and it is open in the gateway that points to the local ip and port.

1 answer

-3

To solve this problem, just follow the following steps. First of all we will install the database in Mysql:

# mysql_install_db

Then you need to generate the Sock:

# chown -R mysql.mysql /var/lib/mysql

Now let’s start the Mysql server:

# safe_mysqld &

Great, your Mysql is already running!

Open another terminal window and type:

# mysql

I hope I’ve helped!

Browser other questions tagged

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