小编Dre*_*old的帖子

如何使用 SSL 从本地主机上的 node.js 连接到在 PlanetScale 上运行的 MySQL 数据库服务器?

我正在尝试连接到 PlanetScale 上的 MySQL 服务器,但无法连接,因为它需要 SSL。

这是他们的文档,但不清楚它说了什么。 https://planetscale.com/docs/concepts/secure-connections

这是连接 URL:DATABASE_URL='mysql://co30rXXXXXXX:pscale_pw_XXXXXXX@hoqx01444p30.us-east-4.psdb.cloud/restaurant?ssl={"rejectUnauthorized":true}'

这是我运行时从终端看到的内容yarn run migration-run

纱线运行v1.22.18 $ npx prisma migrate dev 从.env加载的环境变量 从prisma/schema.prisma加载的Prisma模式数据源“db”:MySQL数据库“restaurant”位于“hoqx0XXXXX.us-east-4.psdb.cloud:3306” ”

错误:迁移引擎错误:未知错误:代码:UNAVAILABLE 服务器不允许不安全连接,客户端必须使用 SSL/TLS

error 命令失败,退出代码 1。 info 请访问 https://yarnpkg.com/en/docs/cli/run以获取有关此命令的文档。

有没有人尝试过从本地主机上的 Node.js 连接到 PlanetScale DB?我尝试了 Stackoverflow 的其他一些建议,但似乎不起作用。

mysql ssl ssl-certificate node.js planetscale

4
推荐指数
1
解决办法
4363
查看次数

MongoServerSelectionError:连接 ECONNREFUSED ::1:27017

当我尝试使用 Mongoose 将我的应用程序与数据库连接时遇到问题。已经尝试过以下我在谷歌上找到的解决方案:

在Windows上重新启动MongoDB服务,使用位于MongoDB的bin文件上的cmd手动打开数据库,但我无法解决它。谁能帮我?

这是我的index.js

const { MongoClient } = require('mongodb')
const url = 'mongodb://localhost:27017';
const database = 'e-comm'
const client = new MongoClient(url);

async function getData()
{
    let result = await client.connect();
    let db = result.db(database);
    let collection = db.collection('products');
    let response =  await collection.find({}).toArray();
    console.log(response);
}
getData();

Run Code Online (Sandbox Code Playgroud)

并抛出错误

C:\Users\HP\new node\node_modules\mongodb\lib\sdam\topology.js:292
                const timeoutError = new error_1.MongoServerSelectionError(`Server selection
 timed out after ${serverSelectionTimeoutMS} ms`, this.description);
                                     ^

MongoServerSelectionError: connect ECONNREFUSED ::1:27017
    at Timeout._onTimeout (C:\Users\HP\new node\node_modules\mongodb\lib\sdam\topology.js:29
2:38)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7) …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js mongo-shell nodemon

2
推荐指数
1
解决办法
2467
查看次数