运行项目一直报这个错,在网上找了一天了,各种方法都试过了,不知道哪里有问题。
配置都是照着课程写的:
const env = process.env.NODE_ENV // 环境参数
// 配置
let MYSQL_CONFIG
if (env === 'dev') {
MYSQL_CONFIG = {
host: 'localhost',
user: 'root',
password:'qwe123cl',
port: '3306',
database: 'myblog',
}
}
报错:
[nodemon] starting `node ./bin/www.js`
Ignoring invalid configuration option passed to Connection: MYSQL_CONFIG. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection
监听在9527端口...
node:events:368
throw er; // Unhandled 'error' event
^
Error: Access denied for user ''@'localhost' (using password: NO)
at Packet.asError (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/packets/packet.js:728:17)
at ClientHandshake.execute (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/commands/command.js:29:26)
at Connection.handlePacket (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/connection.js:456:32)
at PacketParser.onPacket (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/connection.js:85:12)
at PacketParser.executeStart (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.<anonymous> (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/connection.js:92:25)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
Emitted 'error' event on Connection instance at:
at Connection._notifyError (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/connection.js:236:12)
at ClientHandshake.<anonymous> (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/connection.js:125:14)
at ClientHandshake.emit (node:events:402:35)
at ClientHandshake.execute (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/commands/command.js:39:14)
at Connection.handlePacket (/Users/chenlong/Desktop/blog/node_modules/mysql2/lib/connection.js:456:32)
[... lines matching original stack trace ...]
at addChunk (node:internal/streams/readable:315:12) {
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000',
sqlMessage: "Access denied for user ''@'localhost' (using password: NO)",
sql: undefined
}
[nodemon] app crashed - waiting for file changes before starting...
求解决!