Error: connect ECONNREFUSED 127.0.0.1:3306 as AWS EC2 with nodes
See original GitHub issueHi. I have Error and… I look around all of web site. but all of solution didn’t work. My setting is below information.
- AWS : EC2(linux), route53, load balancer
- nodJs with express
- express listen port : 80
- mysql : port 3306 (also, in EC2 security group, I’m authorize RDS server using RDS endpoint).
in my case, a little odd…
because of connecting domain, I should use port 80 in my EC2. but problem is if I set the port 80, then the linux block.
so, I use ‘sudo’, and then it’s work! but, the mysql to call the function give to me error like that Error: connect ECONNREFUSED 127.0.0.1:3306
if I change the express listen port to 3000 then mysql is good work! but another way, If I set the port at express as 3000 and use keyword ‘sudo’, then It will be same error
So, I think problem is related to use keyword ‘sudo’
do you know what happen???
I attach my source code… than you
const app = express();
const port = 3000;
app.use('/', express.static(__dirname + '/../public'));
app.post('/Master', (req, res) => {
var name = req.body.name;
var pwd = req.body.pwd;
db.getMasterid(function(err, results){
if(err) {
res.send(500, "Server get Error from Masterid");
return;
}
var pool = db.createPool({
connectionLimit : 10,
host : process.env.MYSQL_HOST,
user : process.env.MYSQL_USER,
password : process.env.MYSQL_SECRET,
database : process.env.MYSQL_DB,
port : '3306',
ssl : "Amazon RDS",
})
exports.getMasterid = function(callback){
var sql = 'select * from masterid';
pool.getConnection((err, connection) => {
if(err){
console.log(err);
callback(true);
return;
}
connection.query(sql, (err, results, field) => {
connection.release();
if(err){
console.log(err);
callback(true);
return;
}
callback(false, results);
});
});
};
Error Message
{ Error: connect ECONNREFUSED 127.0.0.1:3306
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1081:14)
--------------------
at Protocol._enqueue (/home/ec2-user/mjlens/node_modules/mysql/lib/protocol/Protocol.js:141:48)
at Protocol.handshake (/home/ec2-user/mjlens/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at PoolConnection.connect (/home/ec2-user/mjlens/node_modules/mysql/lib/Connection.js:130:18)
at Pool.getConnection (/home/ec2-user/mjlens/node_modules/mysql/lib/Pool.js:48:16)
at Object.exports.getMasterid (/home/ec2-user/mjlens/build/mysql_db/reservation_db.js:23:10)
at /home/ec2-user/mjlens/build/main.js:111:30
at Layer.handle [as handle_request] (/home/ec2-user/mjlens/node_modules/express/lib/router/layer.js:95:5)
at next (/home/ec2-user/mjlens/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/ec2-user/mjlens/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/ec2-user/mjlens/node_modules/express/lib/router/layer.js:95:5)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true }
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
ECONNREFUSED Node.js server failing to connect to aws ...
It looks like it's trying to connect to 127.0.0.1:3306 but it should be connecting to the DNS address of the RDS instance. –...
Read more >connect ECONNREFUSED 127.0.0.1:3306 solved in Node JS ...
How to fix Error : connect ECONNREFUSED 127.0.0.1:3306 in node js and mysql is shown.
Read more >AWS: How to allow incoming connection mysql ...
When the node app - which runs correctly on server-ip:3000 tries to connect to 127.0.0.1:3306 it fails ( ECONNREFUSED).
Read more >error: connect econnrefused 127.0.0.1:3306
This error occurs when you run an instance of PopSQL or Node.js and the MySQL server is not running on your local machine....
Read more >Use EC2 as a bastion host to locally connect to a private ...
How can I connect to a private Amazon RDS DB instance from a local machine ... Note: To connect one or more EC2...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sidorares Thank you!!!