gpt4 book ai didi

mysql - 连接 ECONNREFUSED - Node js , sql

转载 作者:IT老高 更新时间:2023-10-28 23:15:18 25 4
gpt4 key购买 nike

我在 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)

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

(我正在使用 Windows 7)

谢谢!!

最佳答案

我知道两种解决方法:

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

  2. 尝试这样设置套接字:

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

关于mysql - 连接 ECONNREFUSED - Node js , sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8825342/

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