MySQL可以远程连接,但不能本地连接 [英] MySQL Can Connect Remotely but not Locally
问题描述
这是一个奇怪的问题,我不确定发生了什么.我在运行Ubuntu 10.04 LTS的Linux机器上安装了MySQL.我可以通过SSH mysql -p
访问mysql并以这种方式执行所有命令.我添加了一个用户,可以使用AddedUser
从本机远程连接,但不能从本地计算机远程连接.对我来说没有意义...
This is a weird problem and I'm not sure what's going on. I installed MySQL on a linux box I have running Ubuntu 10.04 LTS. I can access mysql via SSH mysql -p
and perform all my commands that way. I added a user, and I can use AddedUser
to connect remotely from my machine, but not from the local machine. It makes no sense to me...
SELECT host, user FROM mysql.user
产量:
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | AddedUser |
| 127.0.0.1 | root |
| li241-255 | root |
| localhost | debian-sys-maint |
| localhost | root |
+-----------+------------------+
问题是我正在使用Node.js在这台机器上进行开发,并且无法使用相同的用户名从服务器进行本地连接.我已经尝试过FLUSH PRIVILEGES
,但这似乎没有效果.
Problem is I'm developing on this machine using Node.js, and I can't connect locally from the server using the same username. I've tried FLUSH PRIVILEGES
but that seems to have no effect.
我知道它不是Node.js,因为我在另一个数据库上使用了相同的代码,并且它在该环境中正常工作.
I know it's not Node.js because I'm using the same code on another database and it's working in that environment.
这是错误节点给我的消息.
This is the error node is giving me.
node.js:50
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: ECONNREFUSED, Connection refused
at Stream._onConnect (net.js:687:18)
at IOWatcher.onWritable [as callback] (net.js:284:12)
编辑2
我有正确的端口&我可以告诉服务器.我的/etc/mysql/my.cnf
包含以下内容:
Edit 2
I have the right port & server as best I can tell. My /etc/mysql/my.cnf
contains this:
port = 3306
socket = /var/run/mysqld/mysqld.sock
我的MySQL对象包含:
My MySQL object contains:
{ host: 'localhost',
port: 3306,
user: 'removed',
password: 'removed',
database: '',
typeCast: true,
flags: 260047,
maxPacketSize: 16777216,
charsetNumber: 192,
debug: false,
ending: false,
connected: false,
_greeting: null,
_queue: [],
_connection: null,
_parser: null,
server: 'ExternalIpAddress' }
可能有用吗?
netstat -ln | grep mysql
unix 2 [ ACC ] STREAM LISTENING 1016418 /var/run/mysqld/mysqld.sock
推荐答案
Connection Refused
在TCP/IP协议级别发出信号,这意味着您的本地连接尝试使用了错误的主机名和/或(更可能是)端口号.
Connection Refused
is being signaled at the TCP/IP protocol level, and means that your local connection attempt is using the wrong hostname and/or (more likely) port number.
这是另一种(公认的低概率)可能性:
Here's another (admittedly low-probability) possibility:
- 您在JS对象中同时定义了
host
和server
,在这种情况下,node.js可能会优先于server
. - 如果
externalIPaddress
位于NAT防火墙的另一侧,则可能(实际上,应该将)防火墙配置为丢弃进入端口3306的传入流量. - 当您尝试连接时,您的数据包将首先被路由到NAT防火墙,并在那里被丢弃.
- You have both
host
andserver
defined in the JS object, in which case node.js might give precedence toserver
. - If the
externalIPaddress
is on the other side of a NAT firewall, the firewall may be (actually, should be) configured to discard incoming traffic to port 3306. - When you try to connect, your packets are being routed to the NAT firewall first and are being discarded there.
验证是否同时设置了server
和host
不会导致此问题.
Verify that having both server
and host
set will not cause this problem.
这篇关于MySQL可以远程连接,但不能本地连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!