Hi I am new with Sequelize ORM. I am following some tutorial and while hands-on, I am facing the problem in connecting the MySQL database with server.
ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306
at ConnectionManager.connect (G:\projects\chatApp\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:116:17)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
parent: Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
},
original: Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
}
Serve.js
const { ApolloServer } = require('apollo-server')
const { sequelize } = require('./models')
const resolvers = require('./graphql/resolvers')
const typeDefs = require('./graphql/typeDefs')
const server = new ApolloServer({
typeDefs,
resolvers,
})
server.listen().then(({ url }) => {
console.log(`đ Server ready at ${url}`)
sequelize
.authenticate()
.then(() => console.log('Database connected!!'))
.catch((err) => console.log(err))
})
config.json
{
"development": {
"username": "root",
"password": "root",
"database": "database_dev",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
Can anyone tell me why I am not able to connect to the database?
run MySql installer
reconfigure the MySql Server. it will work fine.
check this out
Check port of mysql you are using, maybe 3307 ?
Related
I'm using a vServer from Ionos for a little project. I installed a MariaDB and NodeJS. Currently I'm trying to connect them both. Here is my code:
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: 'localhost',
user:'root',
password: 'xxxxxxxxx',
database: 'christmastrees',
connectionLimit: 5,
});
async function asyncFunction() {
let conn;
try {
conn = await pool.getConnection();
const rows = await conn.query("SELECT * from bÀume");
console.log(rows); //[ {val: 1}, meta: ... ]
} catch (err) {
throw err;
} finally {
if (conn) return conn.end();
}
}
But when executing the file (node app), I get an error message after a few seconds
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
From event:
at _registerHandshakeCmd (/root/server/node_modules/mariadb/lib/connection.js:745:11)
at /root/server/node_modules/mariadb/lib/connection.js:57:11
at new Promise (<anonymous>)
at Connection.connect (/root/server/node_modules/mariadb/lib/connection.js:56:16)
at createConnectionPoolPromise (/root/server/node_modules/mariadb/lib/pool-promise.js:31:8)
at creationTryout (/root/server/node_modules/mariadb/lib/pool-base.js:373:9)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
So I searched for help and after 2 hours I literally found only one Idea. I added this line of code to my connection...
port: '/var/run/mysqld/mysqld.sock'
I tryed again to use node app, but this time I didn't get an error message, it is loading forever and nothing happens.
I would be so grateful for any help...
So I found the solution to my problem.
I checked if my MariaDB Service is even running and no it wasn't ^^
I'm trying to put in production a site I made with Angular and Express/Sequelize, but always have Sequelize errors :
It works perfectly fine in local with WAMP, I can reach my local database and it's all good.
When I'm trying to use my OVH database (that I got with my hosting plan), I have the following errors :
HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
at ConnectionManager.connect (C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:120:17)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async ConnectionManager._connect (C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:318:24)
at async C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:250:32
at async ConnectionManager.getConnection (C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:280:7)
at async C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\sequelize.js:613:26
at async MySQLQueryInterface.createTable (C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\query-interface.js:225:12)
at async Function.sync (C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\model.js:1300:5)
at async Sequelize.sync (C:\Users\Dorian\Desktop\DĂ©veloppement Web\Mes sites\capitales\server\node_modules\sequelize\lib\sequelize.js:793:35) {
parent: Error: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'dodobwtdodob.mysql.db',
fatal: true
},
original: Error: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'dodobwtdodob.mysql.db',
fatal: true
}
}
I don't understand because I've always used the same config, it works fine when I'm using a PHP PDO object on other projects for example. It doesn't work either on my OVH VPS, where I'm getting connection refused error (even if I had to look at all the tutorials on the net), but that's another problem.
Here is my db.config.js :
module.exports = {
HOST: "dodobwtdodob.mysql.db",
USER: "dodobwtdodob",
PASSWORD: "secretpassword",
DB: "dodobwtdodob",
dialect: "mysql",
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
port:3306
};
And here a part of my index.js :
const dbConfig = require("../config/db.config.js");
const Sequelize = require("sequelize");
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
host: dbConfig.HOST,
dialect: dbConfig.dialect,
port: dbConfig.port,
pool: {
max: dbConfig.pool.max,
min: dbConfig.pool.min,
acquire: dbConfig.pool.acquire,
idle: dbConfig.pool.idle
}
});
Please change hostname "dodobwtdodob.mysql.db" to ipAddress(host address).
I have tried to connect to my remote MySQL database server with npm's mysql package but it keeps on throwing this error
But it works fine when I use mysqli with PHP
ERROR:
Error: connect ETIMEDOUT
at PoolConnection.Connection._handleConnectTimeout (/home/rilla/Desktop/dbTest/node_modules/mysql/lib/Connection.js:409:13)
at Object.onceWrapper (events.js:416:28)
at Socket.emit (events.js:310:20)
at Socket._onTimeout (net.js:479:8)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
--------------------
at Protocol._enqueue (/home/rilla/Desktop/dbTest/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/home/rilla/Desktop/dbTest/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at PoolConnection.connect (/home/rilla/Desktop/dbTest/node_modules/mysql/lib/Connection.js:116:18)
at Pool.getConnection (/home/rilla/Desktop/dbTest/node_modules/mysql/lib/Pool.js:48:16)
at Object.<anonymous> (/home/rilla/Desktop/dbTest/test.js:22:6)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
MY CODE:
// Get the mysql service
var mysql = require("mysql");
// Add the credentials to access your database
// var connection = mysql.createConnection({
// host: "my_host", // hosts IP here
// port: 3306,
// user: "my_username",
// password: "my_password",
// database: "my_database",
// });
var pool = mysql.createPool({
connectionLimit: 100,
host: "my_host", // hosts IP here
port: 3306,
user: "my_username",
password: "my_password",
database: "my_database",
});
pool.getConnection(function (err, conn) {
if (err) {
console.log(err);
} else {
console.log('it works now')
}
});
// connect to mysql
// connection.connect(function (err) {
// // in case of error
// if (err) {
// console.log(err);
// console.log(err.code);
// console.log(err.fatal);
// } else {
// console.log('it works now')
// }
// });
I have tried with sequelize too but no avail. I can't figure why it's not connecting
I use the email account of my site contact#monsite.com to send smtp alert messages to the email of my users. but it still gives me this error
Error: connect ECONNREFUSED 127.0.0.1:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 465,
command: 'CONN'
}
here is my code
// send mail function
exports.sendMailer = (optionsTransporterMail = OptionsTransporterMail, optionsMail = OptionsMail, callback) => {
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport(optionsTransporterMail);
transporter.sendMail(optionsMail, function (err, info) {
callback(err, info)
});
}
sendMailer({
service: 'mail.mywebsite.com',
port: 465,
secure: true,
auth: {
user: 'contact#mywebsite.com',
pass: '12345678'
}
}, {
from: '"My app <contact#mywebsite.com>',
to: user#domain.com,
subject: "Notify",
text: "Hello worlds",
html: "Hello worlds"
}, (err, info) => {
if err console.log(err);
console.log(info)
})
it still gives this error
Error: connect ECONNREFUSED 127.0.0.1:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 465,
command: 'CONN'
}
I assume you want to use mail.mywebsite.com in order to send an email. In those terms, you have to set up host value in options, because it seems like by default it uses localhost (127.0.0.1).
Please try the following code:
sendMailer({
host: 'mail.mywebsite.com',
port: 465,
secure: true,
auth: {
user: 'contact#mywebsite.com',
pass: '12345678'
}
}, {
from: '"My app <contact#mywebsite.com>',
to: user#domain.com,
subject: "Notify",
text: "Hello worlds",
html: "Hello worlds"
}, (err, info) => {
if err console.log(err);
console.log(info)
})
When installing a fresh version of xampp I'm able to connect my js script to MySQL through the terminal.
const mysql = require('mysql');
let con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
port:3307
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
PS C:\login> node connection.js
Connected!
I've been trying another db which I have credentials for but it seems to be a problem when you have a password property in the con object. That it will not connect with a password :P What Im I doing wrong here?
C:\login\connection.js:13
if (err) throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16)
--------------------
at Protocol._enqueue (C:\login\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\login\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\login\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (C:\login\connection.js:12:7)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
var mysql = require("mysql");
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database:"xyz"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
PS C:\login> node connection.js
Connected!