我正在尝试与我的node.js服务器建立MySQL连接,但是当我这样做时,我收到以下错误:
import android.app.Application;
public class AppContext extends Application {
private static AppContext mInstance;
public static final String TAG = AppContext.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
@Override
public void onTerminate() {
super.onTerminate();
mInstance = null;
}
public static synchronized AppContext getInstance() {
return mInstance;
}
}
我尝试过使用其他端口,但仍然出现相同的错误消息。当我使用XAMPP并启动MySQL服务时,它连接正常。当我使用npm:
安装mysql时,这些是消息F:\Programmering\nodejs-server>node dbConnection.js
F:\Programmering\nodejs-server\dbConnection.js:10
if (err) throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:3306
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
--------------------
at Protocol._enqueue (F:\Programmering\nodejs-server\node_modules\mysql\lib\
protocol\Protocol.js:145:48)
at Protocol.handshake (F:\Programmering\nodejs-server\node_modules\mysql\lib
\protocol\Protocol.js:52:23)
at Connection.connect (F:\Programmering\nodejs-server\node_modules\mysql\lib
\Connection.js:130:18)
at Object.<anonymous> (F:\Programmering\nodejs-server\dbConnection.js:9:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
我一直在使用w3schools教程。这是我的代码:
F:\Programmering\nodejs-server>npm install mysql
npm WARN nodejs-server@1.0.0 No repository field.
+ mysql@2.15.0
added 11 packages in 7.809s
我做错了什么?请帮忙!谢谢!