简体   繁体   English

本地 mysql 仅在 windows 上连接 ECONNREFUSED

[英]local mysql connect ECONNREFUSED only on windows

I've tried everything, but simply on windows any connection to the database is refused, I used xampp, manp, easyphp and mysql workbench, but everyone had the same problem.我已经尝试了一切,但只是在 windows 上拒绝任何与数据库的连接,我使用了 xampp、manp、easyphp 和 mysql 工作台,但每个人都有同样的问题。 the xampp in linux works perfectly with the same code, however in windows and refused, I tried to turn off the firewall too and give permissions, but it also didn't help, I saw that there was the mysql process, but still nothing. the xampp in linux works perfectly with the same code, however in windows and refused, I tried to turn off the firewall too and give permissions, but it also didn't help, I saw that there was the mysql process, but still nothing.

I am using the following code just to test whether it is connecting.我使用以下代码只是为了测试它是否正在连接。

var mysql = require('mysql');

var con = mysql.createConnection({
  host:"localhost",
  user:"root",
  port: 3306,
  password:""
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});

And the exit和出口

/mnt/d/Projetos/EstudoNode/teste.js:11
  if (err) throw err;
           ^

Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
    --------------------
    at Protocol._enqueue (/mnt/d/Projetos/EstudoNode/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/mnt/d/Projetos/EstudoNode/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/mnt/d/Projetos/EstudoNode/node_modules/mysql/lib/Connection.js:116:18)      
    at Object.<anonymous> (/mnt/d/Projetos/EstudoNode/teste.js:10:5)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true
}

I'm trying to make it work with xampp, I've tried to change the port but in this case windows defender blocks myql from starting.我正在尝试使其与 xampp 一起使用,我尝试更改端口,但在这种情况下 windows 防御者阻止 myql 启动。

I've been trying all kinds of solutions for two days, but I have no idea what to do这两天我一直在尝试各种解决方案,但我不知道该怎么办

edit1: I just noticed that it is also giving this error in xampp, I don't know if it may be influencing the connection.编辑1:我刚刚注意到它在xampp中也出现了这个错误,我不知道它是否会影响连接。

在此处输入图像描述

edit2: I tried to connect with the php code below and I was successful with the connection, so I believe it is some problem with nodejs on windows. edit2:我尝试使用下面的 php 代码连接,并且连接成功,所以我认为 windows 上的 nodejs 存在问题。

<?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $conn = mysqli_connect($servername, $username, $password);
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    echo "Connected successfully";
    mysqli_close($conn);
    ?>

The problem is not part of xampp or any database.问题不是 xampp 或任何数据库的一部分。 the problem and the windows WSL that is not allowing the connection问题和不允许连接的 windows WSL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM