无法使用Sequelize(nodejs)连接到localhost数据库

编程入门 行业动态 更新时间:2024-10-28 19:29:06
本文介绍了无法使用Sequelize(nodejs)连接到localhost数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用SequelizeJS连接并与我的本地主机(MAMP)上的数据库通信。但是,每当我尝试执行查询时,我都会收到此错误: ECONNREFUSED 。我仔细检查了MySQL的端口号和主机名,即3306和localhost。我几乎遵循他们网站上的指南。以下是我的一些代码:

I am using SequelizeJS to connect and talk to my database which is on my localhost (MAMP). However, whenever I try to execute a query, I keep getting this error: ECONNREFUSED. I double checked the port number of MySQL and the host name, which are 3306 and localhost. I pretty much followed the guide that is on their site. Here is some of my code:

var sequelize = new mysql('partythump', 'root', 'mysqlroot', { host: 'localhost', port: 3306, timestamps: false }); var parties = sequelize.define('parties', { id: mysql.INTEGER, party_name: mysql.STRING, party_id: mysql.STRING, created_on: mysql.DATE, is_active: mysql.BOOLEAN, party_code: mysql.STRING, geo_location: mysql.STRING });

在函数中,我有:

var party = parties.build({ id: null, party_name: 'test', party_id: '', is_active: 1, party_code: '', geo_location: '', created_on: new Date() }); party .save() .on('success', function() { console.log('Inserted new party into db'); }) .on('failure', function(error) { console.log('Could not execute insert query'); console.log(error); });

任何人都可以帮助我吗?

Can anyone help me out?

推荐答案

所以,谢谢你的答案,但我的同事最终找到了问题所在。它与MAMP中的配置有关。要解决此问题:

So, thanks for the answers, but my co-worker eventually figured out the problem. It has to do with a configuration in MAMP. To fix this:

在MAMP中,在菜单栏中,转到文件>编辑模板> MySQL myf

In MAMP, in the menu bar, go to File > Edit Template > MySQL myf

在第46行,注释掉:

MAMP_skip-networking_MAMP

现在应该可以工作!

更多推荐

无法使用Sequelize(nodejs)连接到localhost数据库

本文发布于:2023-10-26 14:35:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   数据库   Sequelize   nodejs   localhost

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!