I
I
Ingerniated2018-03-26 00:47:19
MySQL
Ingerniated, 2018-03-26 00:47:19

How to check if a port is busy with something?

Good night, such a problem, there is a mysql server, php with apache can connect to it, but the node cannot, it gives an error waiting for the connection.
How to check if the database is busy with something else that prevents the node from connecting to it?
Here is the error itself.

spoiler
5ab818a9875ae762917240.jpeg

here is the code, for others it works without errors, but for me, after starting, after 30 seconds, an error about disconnecting the connection flies.
var mysql = require('mysql');

  var con = mysql.createConnection({
  	host: "127.0.0.1",
  	user: "root",
  	password: "password",
  	database: "mydb"
  });

  con.connect();

  con.end();

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lynn "Coffee Man", 2018-03-26
@Lynn

Judging by the error, the connection is closing the server because you don't ask it for anything. https://dev.mysql.com/doc/refman/5.5/en/server-sys...
You can try to ping it every 10 seconds so that it doesn't close the connection. https://github.com/mysqljs/mysql/blob/master/Readm...

C
Coder321, 2018-03-26
@Coder321

You have an uncaught error, add a handler and see what kind of error, why guess

D
Danil, 2018-04-10
@Veneomin

You forgot to connect to mysql.

var mysql = require('mysql');

var con = mysql.createConnection({ // <-- это лучше назвать db_config
  	host: "127.0.0.1",
  	user: "root",
  	password: "password",
  	database: "mydb"
});

connection = mysql.createConnection(con); // <-- Вот это ты забыл сделать
connection.connect();
console.log(connection.state); // <-- Вот тут должно написать что все ок.
connection.end();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question