我剛剛開始,所以我對上述兩方面知之甚少。 代碼:Node.js mySQL無法創建連接
var mysql = require("mysql");
var express = require('express');
var app = express();
// First you need to create a connection to the db
var con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: ''
});
con.connect(function(err){
if(err){
console.log('Error connecting to Db');
console.log(err);
return;
}
console.log('Connection established');
});
con.end(function(err) {
// The connection is terminated gracefully
試圖用Node.js的運行它,但它說:
Error connecting to Db
{ Error: connect ECONNREFUSED 127.0.0.1:3306
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
--------------------
at Protocol._enqueue (C:\Users\yeohc\Desktop\Newfolder\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at Protocol.handshake (C:\Users\yeohc\Desktop\Newfolder\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (C:\Users\yeohc\Desktop\Newfolder\node_modules\mysql\lib\Connection.js:130:18)
at Object.<anonymous> (C:\Users\yeohc\Desktop\Newfolder\app.js:13:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true }
請幫我和記住,我剛開始在編程的東西。在此之前感謝您的幫助
你能夠在控制檯上連接mysql客戶端嗎? – abdulbarik