gpt4 book ai didi

mysql - Eclipse Che 中的 MySQL 运行时拒绝连接

转载 作者:行者123 更新时间:2023-11-30 21:55:40 26 4
gpt4 key购买 nike

我正在尝试从 multi-machine workspace 中的另一个 NodeJS 运行时连接到 MySQL 运行时中的数据库.

在测试中,我使用目标用户列表调用 API http://localhost:3000/target。此 API 中的代码在数据库上运行 SELECT:

...

exports.list = function(req, res) {

req.getConnection(function(err, connection) {

if (err) {
console.log("MySQL " + err);
} else {

connection.query('SELECT id FROM target', function(err, rows) {

if (err) {
console.log("Error Selecting : %s ", err);
} else {

...

我从终端得到的结果:

get target list from http://localhost:3000/target
MySQL Error: connect ECONNREFUSED 127.0.0.1:3306

这里我定义了到数据库的连接:

var express = require('express');
var connection = require('express-myconnection');
var mysql = require('mysql');
var config = require('config');
var connectionConfig = config.get('mysql');
var connectionInstance = connection(mysql, connectionConfig, 'request');

...

app.use(connectionInstance);

app.get('/', function(req, res) {
res.send('Welcome');
});

app.get('/target', target.list);

....

配置:

{
"mysql": {
"host": "localhost",
"user": "[user]",
"password": "[password]",
"database": "[database]"
},
"app": {
"port": 3000,
"server": "http://localhost"
}
}

这是我在 Eclipse Che 的数据库机器配置中的内容:

snapshot of servers configuration

这是我的食谱:

服务:
D b:
图片:eclipse/mysql
环境:
MYSQL_ROOT_PASSWORD:密码
MYSQL_DATABASE:宠物诊所
MYSQL_USER:宠物诊所
MYSQL_PASSWORD:密码
MYSQL_ROOT_USER:根用户
内存限制:1073741824
开发机:
图片: eclipse /Node
内存限制:2147483648
依赖于取决于:
- D b
Elasticsearch :
图片:florentbenoit/cdvy-ela-23
内存限制:2147483648

最佳答案

你能分享你的多机工作区的配方吗?这对调试它有很大帮助。

只是一个猜测:我认为您设置的问题是使用 localhost 作为您的数据库连接。如果您正在运行多机设置,则数据库在不同的 docker 容器中运行,需要通过其名称进行寻址。

摘自多机教程:

In the recipe the depends_on parameter of the “dev-machine” allows it to connect to the “db” machine MySQL process’ port 3306. The “dev-machine” configures its MySQL client connection in the projects source code at src/main/resources/spring/data-access.properties. The url is defined by jdbc.url=jdbc:mysql://db:3306/petclinic which uses the database machine’s name “db” and the MySQL server default port 3306.

您需要在您的配方中配置开放端口。

免责声明:我不直接隶属于 Eclipse Che、Codenvy 或 Red Hat,但我们正在构建我们的 own cloud IDE for C/C++ multicore optimization在 Eclipse Che 之上。

关于mysql - Eclipse Che 中的 MySQL 运行时拒绝连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45284395/

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