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

查看:81
本文介绍了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'ing到端口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天全站免登陆