我在windows上運行Node.js 0.10.31
,在192.168.2.150上運行的虛擬機ubuntu上運行我的mySQL 5.5.35
。現在節點JS連接到MySQL我已經使用以下連接器:無法將nodejs連接到mysql
https://github.com/felixge/node-mysql
代碼:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '192.168.2.150',
user : 'root',
password : '*****',
port : 3306
});
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
connection.query('SELECT 1', function(err, rows) {
// connected! (unless `err` is set)
console.log(err, rows);
});
在my.cnf文件bind address
是0.0.0.0。此外,在用戶表中,我已將所有數據庫的權限授予[email protected]
。但是,我仍然無法從節點連接到MySQL,並且它給出了以下錯誤。 我甚至嘗試過Node js 0.8.2版本,但仍然無法正常工作。任何人都可以指出錯誤?
錯誤:
error connecting: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'
192.168.2.99' (using password: YES)
at Handshake.Sequence._packetToError (G:\Coding_Zone\NodeJs_Work\Output\node
_modules\mysql\lib\protocol\sequences\Sequence.js:48:14)
at Handshake.ErrorPacket (G:\Coding_Zone\NodeJs_Work\Output\node_modules\mys
ql\lib\protocol\sequences\Handshake.js:101:18)
at Protocol._parsePacket (G:\Coding_Zone\NodeJs_Work\Output\node_modules\mys
ql\lib\protocol\Protocol.js:271:23)
at Parser.write (G:\Coding_Zone\NodeJs_Work\Output\node_modules\mysql\lib\pr
otocol\Parser.js:77:12)
at Protocol.write (G:\Coding_Zone\NodeJs_Work\Output\node_modules\mysql\lib\
protocol\Protocol.js:39:16)
at Socket.Connection.connect (G:\Coding_Zone\NodeJs_Work\Output\node_modules
\mysql\lib\Connection.js:82:28)
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:397:14)
--------------------
at Protocol._enqueue (G:\Coding_Zone\NodeJs_Work\Output\node_modules\mysql\l
ib\protocol\Protocol.js:135:48)
at Protocol.handshake (G:\Coding_Zone\NodeJs_Work\Output\node_modules\mysql\
lib\protocol\Protocol.js:52:41)
at Connection.connect (G:\Coding_Zone\NodeJs_Work\Output\node_modules\mysql\
lib\Connection.js:109:18)
at Object.<anonymous> (G:\Coding_Zone\NodeJs_Work\Output\mySqlTest.js:9:12)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
{ [Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'192.168.2.99' (
using password: YES)]
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000',
fatal: true } undefined
更新:
我曾嘗試與其他用戶還並在數據庫中給予他們充分的權限。但仍然無法解決錯誤。 但奇怪的是我能夠連接到MySQL客戶端
你解決這個問題?如果是的話,請選擇一個答案。 – codecowboy 2015-11-22 09:56:55