我是node.js的新手我最初计划使用PHP,但希望获得节点方面的经验。 我试图连接时尝试使用Node.js连接到MySQL数据库我得到以下错误。
感谢您的帮助!!
这是JS代码
var mysql = require('mysql')
var con = mysql.createConnection({
host: 'localhost',
user: 'lcoleman0422',
password:'Micheal4',
database:'Top Level',
port:3306
});
con.connect();
/* function(err){
if (err) throw err
con.query('select * from Customer',function(error,result){
if(error)throw error;
console.log(result[0].First_Name);
}
)
});*/
con.end();
这是我的MYSQL_Connection.js
中的代码Connected
events.js:182
throw er; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (/home/lcoleman0422/node_modules/mysql/lib/protocol/Protocol.js:113:13)
at Socket.<anonymous> (/home/lcoleman0422/node_modules/mysql/lib/Connection.js:109:28)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
lcoleman0422@p3plcpnl0867 [~/public_html/js]$