简体   繁体   中英

How to Solve Connection Problem Sequelize

i am new at sequelize orm, and i am using mysql database and try to connection with my database but i don't get any connection or any error could someone can figerout whats goes wrong with my code this is the sequelize documention link https://sequelize.org/docs/v6/getting-started/


import {Sequelize} from 'sequelize';


const dbConfig={
        "dbName":"mydb",
        "dbUser":"root",
        "bdHost":"localhost",
        "dbPassword":"Dell@8054",
        "dbPort":"3306",
        "dialect":"mysql"
        };


const sequelize = new Sequelize(dbConfig.db, dbConfig.dbUser, dbConfig.dbPassword, {
    host: dbConfig.bdHost,
    dialect: dbConfig.dialect,
    port:3306
  });
 
 sequelize
  .authenticate().then(con=>{console.log("con",con)}).catch(err=>{console.log("err",err)})

Output of console is -- con undefined

i am expecting to get reponse if connection successfull or any error

you can use

sequelize
.authenticate()
.then(() => {
   logger.info('MySQL connection has been established successfully.')  
})  
.catch(err => {
   logger.error('Unable to connect to the database:', err);
   process.exit(2)  
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM