连接 ECONNREFUSED - 节点 js , sql

connect ECONNREFUSED - node js , sql(连接 ECONNREFUSED - 节点 js , sql)

本文介绍了连接 ECONNREFUSED - 节点 js , sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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',});

这篇关于连接 ECONNREFUSED - 节点 js , sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:连接 ECONNREFUSED - 节点 js , sql

基础教程推荐