bug背景:使用sequelize鏈接mysql數據庫javascript
錯誤信息以下:大概意思是數據庫驗證未經過html
Unhandled rejection SequelizeConnectionError: Client does not support authentication protocol requested by server; consider upgrading MySQL clientjava
C:\Users\Administrator>mysql -u root -pnode
Enter password: ******mysql
Welcome to the MySQL monitor. Commands end with ; or \g.sql
Your MySQL connection id is 18數據庫
Server version: 8.0.11 MySQL Community Server - GPLexpress
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.app
Oracle is a registered trademark of Oracle Corporation and/or itside
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 }