连接 ECONNREFUSED - 节点 js , sql

2021-11-20 00:00:00 node.js mysql

我在 js 文件中有下一段代码:

var mysql = require('mysql');
var TEST_DATABASE = 'nodejs_mysql_test';
var TEST_TABLE = 'test';
var client = mysql.createClient({
  user: 'root',
  password: 'root',
});

client.query('CREATE DATABASE '+TEST_DATABASE, function(err) {
  if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
    throw err;
  }
});

但我收到此错误:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
          ^
Error: connect ECONNREFUSED
    at errnoException (net.js:632:11)
    at Object.afterConnect [as oncomplete] (net.js:623:18)

据我所知,这是一个连接问题 - 但我该如何解决?

As I understand it, this is a connection problem - but how do I solve it?

(我在 Windows 7 上工作)

( I'm working on windows 7)

谢谢!!

推荐答案

我知道两种解决方法:

  1. mysql.conf中,注释skip-networking.

尝试像这样设置套接字:

Try to set the socket like this:

var client = mysql.createClient({
user: uuuu,
password: pppp,
host: '127.0.0.1',
port: '3306',
_socket: '/var/run/mysqld/mysqld.sock',});

相关文章