mysql 使用 node express 在数字海洋中设置
mysql setup in digital ocean using node express
我刚刚决定从 google sql 切换到在我的应用程序所在的 Droplet 上托管我自己的 mysql 服务器,因为 google sql 是side/start up 项目太贵了。
无论如何,我的问题是,我不知道如何使用我的应用程序连接到 mysql。我可以使用终端访问 mysql,我也设法在 workbench 上设置它,但我无法让应用程序连接到它。
这是我的配置对象
DB_HOST=127.0.0.1
DB_USER=root
DB_PASSWORD=*****
DB_NAME=express_mysql_database00
问题:
- 我需要这些列表项吗?
- 数据库主机正确吗?
- 我正在使用 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?
这取决于您如何配置数据库。 localhost
和127.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?
看起来这是你可以使用的...
我刚刚决定从 google sql 切换到在我的应用程序所在的 Droplet 上托管我自己的 mysql 服务器,因为 google sql 是side/start up 项目太贵了。
无论如何,我的问题是,我不知道如何使用我的应用程序连接到 mysql。我可以使用终端访问 mysql,我也设法在 workbench 上设置它,但我无法让应用程序连接到它。
这是我的配置对象
DB_HOST=127.0.0.1
DB_USER=root
DB_PASSWORD=*****
DB_NAME=express_mysql_database00
问题:
- 我需要这些列表项吗?
- 数据库主机正确吗?
- 我正在使用 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?
这取决于您如何配置数据库。 localhost
和127.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?
看起来这是你可以使用的...