S
S
sashavol2017-02-18 18:47:51
MySQL
sashavol, 2017-02-18 18:47:51

Mysql module not connecting to my hosting (mysql)?

Hello!
I have this code:

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'ip моего хостинга',
  user     : 'имя юзера',
  password : 'пароль',
  database : 'имя базы'
});

connection.connect();

var query = connection.query('SELECT * FROM `wp_posts` WHERE `post_type` = "job" limit 1,50', function(err, result) {
  console.log(err);
  console.log(result);
});

connection.end();

But it gives me an error:
$ node sql.js
{ [Error: connect ETIMEDOUT]
  errorno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  fatal: true }
undefined

What do you think could be the problem? I do everything locally.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
niksee, 2017-02-18
@niksee

hint

var mysql = require('mysql');
 
var connection = mysql.createConnection(
    {
      host     : 'localhost',
      user     : 'your-username',
      password : 'your-password',
      database : 'wordpress',
    }
);
 
connection.connect();
 
var query = connection.query('SELECT * FROM wp_posts');
 
query.on('error', function(err) {
    throw err;
});
 
query.on('fields', function(fields) {
    console.log(fields);
});
 
query.on('result', function(row) {
    console.log(row.post_title);
});
 
connection.end();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question