我可以从sqlyog连接数据库,但是当从nodejs连接时出现以下错误:
数据库IP:10.0.0.200
Error when connecting to db: { Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'myuser'@'10.0.0.100' to database 'db_new'
at Handshake.Sequence._packetToError (\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (\node_modules\mysql\lib\protocol\sequences\Handshake.js:103:18)
at Protocol._parsePacket (\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
--------------------
at Protocol._enqueue (\node_modules\mysql\lib\protocol\Protocol.js:145:48)
at Protocol.handshake (\node_modules\mysql\lib\protocol\Protocol.js:52:23)
at Connection.connect (\node_modules\mysql\lib\Connection.js:130:18)
at Timeout.handleDisconnect [as _onTimeout] (\techdoc-connection.js:25:16)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
code: 'ER_DBACCESS_DENIED_ERROR',
errno: 1044,
sqlMessage: 'Access denied for user \'myuser\'@\'10.0.0.100\' to database \'db_new\'',
sqlState: '42000',
fatal: true }
连接数据库的代码
connection = mysql.createConnection({
host: settings.dbhost,
user: settings.user,
password: settings.password,
database: settings.database
});
答案 0 :(得分:0)
遇到此问题时,一个常见的问题是未授予用户所有特权。要授予所有特权,您可以按照mysql的建议执行SQL命令,
mysql> show grants;
+-------------------------------------------------------------------------------------------------------------+
| Grants for RollingRidge@% |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'RollingRidge'@'%' IDENTIFIED BY PASSWORD '*REDACTED' |
| GRANT ALL PRIVILEGES ON `rollingridge`.* TO 'RollingRidge'@'%' |
+-------------------------------------------------------------------------------------------------------------+
希望这会有所帮助。