node.js mysql 错误:ECONNREFUSED [英] node.js mysql error: ECONNREFUSED

查看:41
本文介绍了node.js mysql 错误:ECONNREFUSED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我连不上mysql服务器?

Why can't I connect to the mysql server?

在同一台服务器上运行一个 Apache/PHP 服务器并且它连接没有问题!?

On the same server an Apache/PHP server is running and it connects without problems!?

var mysql_link = {
    host : 'localhost',
    port : 3308,
    database: 'nodetest',
    user : 'root',
    password : 'xxx'
};

var connection = mysql.createConnection(mysql_link);

connection.connect(function(err){
    console.log(err);
    if(err != null){
        response.write('Error connecting to mysql:' + err+'\n');
    }
});

connection.end();

错误

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  fatal: true }

更新

root@dyntest-amd-6000-8gb /var/www/node/dyntest # ps ax | grep mysqld
 7928 pts/0    S+     0:00 grep mysqld
28942 ?        S      0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid
29800 ?        Sl    17:31 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql/mysql-error.log --open-files-limit=65535 --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306

推荐答案

如果这以前有效,我的第一个猜测是您已经获得了在后台运行的 node.js 脚本的副本,该脚本持有连接.

If this has worked before, my first guess would be that you've already got a copy of your node.js script running in the background which is holding the connection.

我认为连接被拒绝是一条 tcp/ip 错误消息,而不是来自 MySQL 的消息,表明它没有运行或正在另一个端口或套接字上运行.

I believe connection refused is a tcp/ip error message, rather than something from MySQL which suggests that it is either not running or is running on another port or with sockets.

您可以尝试 telnet 到 3308 端口吗?查看服务器是否在该端口上运行?

Could you try telnet'ing to port 3308? To see if the server is running on that port?

telnet localhost 3308

你也可以试试:

mysql -hlocalhost -uroot -pxxx

这篇关于node.js mysql 错误:ECONNREFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆