Error: connect ECONNREFUSED Ip address:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
--------------------
at Protocol._enqueue (/App Directory Pat /node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/**App Directory Path**/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/**App Directory Path**/node_modules/mysql/lib/Connection.js:119:18)
at Object.<anonymous> (/var/www/html/app/videostatus/app.js:17:12)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
This is my node.js code
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!');
}).listen(3006);
var mysql = require('mysql');
var connection = mysql.createConnection({
host: '',
user: '',
password: '',
database: ''
});
connection.connect((err) => {
if (err) {
return console.error(err);
}
});
connection.query('SELECT * FROM category_master where category_isactive = 1 ORDER BY `order` ASC', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.end();
Please help me i have spend 2 days but not found anything.
Thank you.
4
Answers
Your MySQL server is not appearing to be running.
If you’re sure it’s running, then you’re using the wrong
host
in yourmysql.createConnection()
. You should use127.0.0.1
, but you may also trylocalhost
or::1
. (IPv6 equivalent of127.0.0.1
).Sometimes you have to look at the port number or checking the entire database connection credentials.
I fixed that bug with the port number, which wasn’t matched before.
Please Check your internet connection if you are providing an IP inside DB Host attribute :
Like :
I used local ip ‘127.0.0.1’ instead of ‘localhost’ it is working for me.
My config.