bug背景:使用sequelize连接mysql数据库
错误信息如下:大概意思是数据库验证未通过
Unhandled rejection SequelizeConnectionError: Client does not support authentication protocol requested by server; consider upgrading MySQL client
C:\Users\Administrator>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.11 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use db
Database changed
mysql> alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1
23456' ;
Query OK, 0 rows affected (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
done!
贴js
const Sequelize = require('sequelize');
const sequelize = new Sequelize('db', 'root', '123456', {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// SQLite only
//storage: 'path/to/database.sqlite',
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
});
const User = sequelize.define('user', {
username: Sequelize.STRING,
birthday: Sequelize.DATE
});
sequelize.sync()
.then(() => User.create({
username: 'janedoe',
birthday: new Date(1980, 6, 20)
}))
.then(jane => {
console.log(jane.toJSON());
});
F:\node_wp\express_wp\myapp\db>node test.js
Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER NOT NULL auto_increment , `username` VARCHAR(255), `birthday` DATETIME, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `users`
Executing (default): INSERT INTO `users` (`id`,`username`,`birthday`,`createdAt`,`updatedAt`) VALUES
(DEFAULT,'janedoe','1980-07-19 16:00:00','2018-07-25 05:31:33','2018-07-25 05:31:33');
{ id: 1,
username: 'janedoe',
birthday: 1980-07-19T16:00:00.000Z,
updatedAt: 2018-07-25T05:31:33.750Z,
createdAt: 2018-07-25T05:31:33.750Z }