所以我一直在尝试从我的 Electron 应用程序连接到 MySQL 数据库:
<script>
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '*********',
user : '******',
password : '******',
port : '******',
debug : 'true'
});
console.log('trying to connect to DB')
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
connection.end()
</script>
我的代码卡在connection.connect上,大约1分钟后它给了我:
error connecting: Error: read ECONNRESET
at exports._errnoException (util.js:1024:11)
at TCP.onread (net.js:610:25)
我不知道该怎么办,有人有什么想法吗?
最佳答案
很可能您的 lan 上的 mssql 实例未配置为允许连接到除本地计算机(即安装 mssql 的计算机)之外的任何设备。
要允许来自 LAN 的连接,您需要编辑以下内容:
编辑my.conf并在[mysqld]部分找到bind-address参数,这可能会被设置为localhost或127.0.0.1,你可以将其更改为你想要连接的机器的IP数据库,或使用通配符并允许整个本地范围,例如 192.168.0.* 或 0.0.0.0
您需要授予对尝试连接的数据库的访问权限
GRANT ALL ON <local database name>.* TO <user>@<iptryingtoconnectfrom> IDENTIFIED BY '<database user password>';
重新启动 mysql 服务就可以了。
关于javascript - 尝试使用 Node.js 和 mysql javascript 客户端连接到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50162740/