Answer the question
In order to leave comments, you need to log in
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.
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
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...
You have an uncaught error, add a handler and see what kind of error, why guess
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 questionAsk a Question
731 491 924 answers to any question