因此,我关注了以下视频:https://www.youtube.com/watch?v=XuLRKMqozwA
我的代码如下:
var mysql = require('mysql');
var con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database: 'articles'
});
con.connect();
我在文件所在的目录中键入了npm install mysql
。
然后键入node new
new 是文件名。
我收到的错误完全如下:
events.js:174
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1104:14)
--------------------
at Protocol._enqueue (C:\Test\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Test\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Test\node_modules\mysql\lib\Connection.js:118:18)
at Object.<anonymous> (C:\Test\new.js:10:5)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
Emitted 'error' event at:
at Connection._handleProtocolError (C:\Test\node_modules\mysql\lib\Connection.js:425:8)
at Protocol.emit (events.js:189:13)
at Protocol._delegateError (C:\Test\node_modules\mysql\lib\protocol\Protocol.js:390:10)
at Handshake.<anonymous> (C:\Test\node_modules\mysql\lib\protocol\Protocol.js:153:12)
at Handshake.emit (events.js:189:13)
at Handshake.Sequence.end (C:\Test\node_modules\mysql\lib\protocol\sequences\Sequence.js:78:12)
at Protocol.handleNetworkError (C:\Test\node_modules\mysql\lib\protocol\Protocol.js:361:14)
at Connection._handleNetworkError (C:\Test\node_modules\mysql\lib\Connection.js:420:18)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
我能找到的所有其他“解决方案”对我都没有用。我做错了很简单,因为我显然没有很多经验。任何事情都会有所帮助。