[英]Trying to connect to a MySQL database using Node.js and the mysql javascript client
所以我一直试图从我的电子应用程序连接到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)
我不知道该怎么办,任何人都有什么主意?
可能是您的局域网上的mssql实例未配置为允许连接到除本地计算机(即安装了mssql的计算机)以外的任何对象。
要允许来自局域网的连接,您需要编辑以下内容:
编辑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服务,您应该一切顺利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.