mysql SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

dkqlctbz  于 2022-12-22  发布在  Mysql
关注(0)|答案(7)|浏览(367)

I'm using Sequelize as an ORM to my node js app and Mysql database , after following some tutorials i m adding this code to connect mysql to the node but after taping npm start i m getting this error : Unable to connect to the database: { SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

const Sequelize = require('sequelize');

 // Option 1: Passing parameters separately
 const sequelize = new Sequelize('Education', 'root','', {
 host: '127.0.0.1',
 dialect: 'mysql'
 } );

  //test db 
 sequelize
.authenticate()
.then(() => {
  console.log('Connection has been established successfully.');
})
 .catch(err => {
 console.error('Unable to connect to the database:', err);
});
ozxc1zmp

ozxc1zmp1#

I have removed port option and issue is resolved.

const sequelize = new Sequelize('dbname', 'dbuser', 'pass', {
    dialect: 'mysql',
    host: "127.0.0.1",
    operatorAlias:false,
    logging:false,
    pool: {
        max: 5,
        idle: 30000,
        acquire: 60000,
    },
    
})
8mmmxcuj

8mmmxcuj2#

Problem solved i was using port : 3307 in phpMyadmin instead of 3306

lymgl2op

lymgl2op3#

Add socketPath in the dialect options
Example code snippet:

// Option 1: Passing parameters separately
const sequelize = new Sequelize('Education', 'root', '', {
  host: '127.0.0.1',
  dialect: 'mysql',
  dialectOptions: {
    socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock'
  }
});
t0ybt7op

t0ybt7op4#

FIX for Node.js use:
It looks as though the current version of sequelize (7) only works on Node.js versions ^12.22.0 , ^14.17.0 & ^16.0.0 . www.sequelize.org says that some other versions may work as well.
Use NVM to install and switch to version 16.0.0:
If you don't already have node version manager you can install it with

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Then install version 16 with nvm i 16.0.0 and then tell your application to use it with nvm use 16.0.0 .

jv4diomz

jv4diomz5#

If you're running XAMMP server on windows, first start apache server with MySQL
You get this error probably because your server is not running.
check your server and restart if necessary.

xwbd5t1u

xwbd5t1u6#

Just restart the mysql server.
Linux and Mac:
service mysql restart
Windows:
Open the Run window by using the Windows+R keyboard. Second, type services.msc and press Enter: Find mysql and restart the service.

bxfogqkk

bxfogqkk7#

**the solution is just only Start Your Xampp Apache and MySQL Service.

**

相关问题