gpt4 book ai didi

使用 Node Express 在 digital ocean 中设置 mysql

转载 作者:行者123 更新时间:2023-11-29 18:00:08 25 4
gpt4 key购买 nike

我刚刚决定从 google sql 切换到在我的应用程序所在的 Droplet 上托管我自己的 mysql 服务器,因为 google sql 对于副业/启动项目来说非常昂贵。

无论如何,我的问题是,我不知道如何使用我的应用程序连接到 mysql。我可以使用终端访问 mysql,我还设法在工作台上设置它,但我无法让应用程序连接到它。

这是我的配置对象

DB_HOST=127.0.0.1 
DB_USER=root
DB_PASSWORD=*****
DB_NAME=express_mysql_database00

问题:

  1. 列表项是我所需要的吗?
  2. 数据库主机正确吗?
  3. 我正在使用 mysql 模块,我需要使用不同的模块才能完成这项工作吗?

最佳答案

来自readme of the mysql npm package ,这些是您需要的参数(还有很多参数,您很可能默认值适合您):

var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});

it the db host correct?

这取决于您如何配置数据库。 localhost127.0.0.1 之间存在差异。请参阅:Mysql localhost != 127.0.0.1?

i'm using the mysql module, do i need to use a different one to make this work?

看起来你可以使用这个...

关于使用 Node Express 在 digital ocean 中设置 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48439588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com