Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在计算机脱机时将nodeJS连接到MySQL_Mysql_Node.js_Electron - Fatal编程技术网

在计算机脱机时将nodeJS连接到MySQL

在计算机脱机时将nodeJS连接到MySQL,mysql,node.js,electron,Mysql,Node.js,Electron,当计算机脱机时,我的Electron应用程序无法连接到本地MySQL。 当计算机连接到internet时,一切正常。 仅在Windows上测试 在nodeJS(命令提示符)和Electron中也会发生同样的情况 代码: s = {database: "test", user: "test", password: "test", host: "localhost"} var mysql = require('./mysql'); var mysqlc = mysql.createConnectio

当计算机脱机时,我的Electron应用程序无法连接到本地MySQL。
当计算机连接到internet时,一切正常。
仅在Windows上测试
在nodeJS(命令提示符)和Electron中也会发生同样的情况

代码:

s = {database: "test", user: "test", password: "test", host: "localhost"}
var mysql = require('./mysql');
var mysqlc = mysql.createConnection(settings);
mysqlc.connect(function(err) { console.log(err); });
错误代码为:

{ [Error: getaddrinfo ENOENT localhost:3306]
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'getaddrinfo',
hostname: 'localhost',
host: 'localhost',
port: 3306,
fatal: true }
为什么?

对此我能做些什么?

当Windows未连接到网络时,它在将
localhost
解析为物理IP地址时遇到问题。显然,在Windows上,当您提供地址
localhost
时,它会将其传递给一个完整的DNS解析程序,该解析程序需要连接到internet才能正常工作

在这里找到了一个关于可能原因的好答案:

尝试使用IP地址本身:

s = {database: "test", user: "test", password: "test", host: "127.0.0.1"}
var mysql = require('./mysql');
var mysqlc = mysql.createConnection(settings);
mysqlc.connect(function(err) { console.log(err); });

我在这里找到了一个关于这个问题的讨论,可能会有所帮助:@Mike-谢谢!使用127.0.0.1确实解决了这个问题。