Bug描述
(node:18548) [DEP0126] DeprecationWarning: timers.active() is deprecated. Please use timeout.refresh() instead.
C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\Parser.js:80
throw err; // Rethrow non-MySQL errors
^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
at Handshake.Sequence._packetToError (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\sequences\Handshake.js:130:18)
at Protocol._parsePacket (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\Connection.js:103:28)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
at Socket.Readable.push (_stream_readable.js:209:10)
--------------------
at Protocol._enqueue (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\Protocol.js:145:48)
at Protocol.handshake (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\protocol\Protocol.js:52:23)
at Connection.connect (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\mysql\lib\Connection.js:130:18)
at Driver.connect (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\orm\lib\Drivers\DML\mysql.js:60:10)
at Object.exports.connect (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\orm\lib\ORM.js:128:10)
at Object.module.exports (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\orm\lib\Express.js:12:6)
at Object.exports.express (C:\Users\Administrator\Desktop\heima_shop_server\node_modules\orm\lib\ORM.js:39:30)
at Object.<anonymous> (C:\Users\Administrator\Desktop\heima_shop_server\src\app.js:17:7)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) {
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlMessage: "Access denied for user 'root'@'localhost' (using password: YES)",
sqlState: '28000',
fatal: true
}
可能原因一
模拟后台app.js
密码问题
即为:连接密码与数据库密码要相对应
'use strict'
var path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const fs = require('fs')
let app = express()
// 注册 body-parser 中间件
app.use(bodyParser({ extended: false }))
// app.use(bodyParser.urlencoded({ extended: false }));
//1.0 初始化orm
const orm = require('orm')
app.use(
orm.express('mysql://root:root@127.0.0.1:3306/dtcmsdb4', {
define: function(db, models, next) {
next()
}
})
)
//2.0 将所有api的请求响应content-type设置为application/json
app.all('/api/*', (req, res, next) => {
//设置允许跨域响应报文头
//设置跨域
//res.header("Access-Control-Allow-Origin", "*");
//res.header("Access-Control-Allow-Headers", "X-Requested-With"); // X-Requested-With
//res.header("Access-Control-Allow-Methods", "*");
res.header('Access-Control-Allow-Origin', '*')
// 设置服务器支持的所有头信息字段
res.header(
'Access-Control-Allow-Headers',
'Content-Type,Content-Length, Authorization, Accept,X-Requested-With'
)
// 设置服务器支持的所有跨域请求的方法
res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
res.setHeader('Content-Type', 'application/json;charset=utf-8')
next()
})
//2.0 设置路由规则
const apiRoute = require('./routes/apiRoute.js')
app.use('/', apiRoute)
app.use(express.static(path.join(__dirname, 'public')))
app.listen(8082, () => {
console.log('vue-cms的api服务已启动, :8082');
});
可能原因二
node.js
版本问题,将其改为最新版本即可
查看版本 node -v