mac连接mysql报错
来源:6-3 数据库操作(更新)
发烧的冬瓜
2022-05-10
运行项目一直报这个错,在网上找了一天了,各种方法都试过了,不知道哪里有问题。
配置都是照着课程写的:
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...
求解决!
写回答
3回答
-
双越
2022-05-12
你直接把这两行删掉,看可以吗?
022022-05-13 -
双越
2022-05-11
看你报错信息
Error: Access denied for user ''@'localhost' (using password: NO)
用户名是空的,应该是 root 才对。
你 debug 一下代码,看最后连接数据库的时候,用户名是什么?
042022-05-12 -
双越
2022-05-11
你打印一下你代码中的 env 是什么值?是不是 'dev' ?
012022-05-11
相似问题