node.js mysql error: ECONNREFUSED(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:node.js mysql 错误:ECONNREFUSED
基础教程推荐
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01