Error using Mysql Sequelize

Asked

Viewed 235 times

0

Code to establish connection to the database:

const Sequelize = require('sequelize')
// Conexão com o banco de dados MySQL
  const sequelize = new Sequelize('postagens', 'root', 'mafikgod123@', {
    host: "localhost",
    dialect: "mysql"
  })

module.exports = {
  Sequelize: Sequelize,
  sequelize: sequelize
}

Model post:

const db = require('./db')

const Post = db.sequelize.define('postagens', {
    titulo: {
        type: db.Sequelize.STRING
    },
    conteudo: {
        type: db.Sequelize.TEXT
    }
})

Post.sync({force: true})

Error:

Unhandled rejection SequelizeConnectionError: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Promise.tap.then.catch.err (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:133:19)
    at tryCatcher (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\promise.js:517:31)
    at Promise._settlePromise (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\promise.js:574:18)
    at Promise._settlePromise0 (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\promise.js:619:10)
    at Promise._settlePromises (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\promise.js:695:18)
    at _drainQueueStep (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\async.js:138:12)
    at _drainQueue (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues (C:\Users\wesley\Desktop\CURSO-NODE\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

1 answer

0


Adapted from Stack Overflow in English:

If you are using Mysql 8x, the problem is in the new form of authentication, which is not supported by most drivers current.

To fix, you must modify the authentication form. To do this, you have to execute the following command in Mysql:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Being password the new password you will use to access the user root. If you are using another user, simply modify the root in the above command by the desired user.

Don’t forget to make one backup if you are working with data from a production environment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.