Ip4address不适用于node-mysql连接ubuntu

时间:2015-05-21 07:35:48

标签: mysql node.js node-mysql

我可以使用localhost和IP4地址打开phpmyadmin:

  1. http://localhost/phpmyadmin

  2. http://192.168.3.72/phpmyadmin

  3. http://127.0.0.1/phpmyadmin/
  4. 以上所有作品

    但是当我尝试将IP4地址应用于此

    var mysql      = require('mysql');
    var connection = mysql.createConnection({
      host     : 'localhost',
      user     : 'me',
      password : 'secret'
    });
    

    参考:https://github.com/felixge/node-mysql/#introduction

    我收到错误:

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

    我做错了什么?

    使用的端口是:

    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State      
    tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
    tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
    tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN     
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
    tcp        0      0 127.0.0.1:28017         0.0.0.0:*               LISTEN     
    tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN     
    tcp6       0      0 ::1:631                 :::*                    LISTEN     
    tcp6       0      0 :::80                   :::*                    LISTEN     
    

    我尝试了netstat -nlt | grep 3306

    但我得到空白输出而不是:

    mysqld  1046  mysql  10u  IPv4  5203  0t0  TCP  xxx.xxx.xxx.xxx:3306 (LISTEN)
    

    试用这篇文章时:  Remote Connections Mysql Ubuntu

    但是当尝试使用:netstat -tulpn | grep :3306

    我输出为:

    tcp        0      0 192.168.3.72:3306       0.0.0.0:*               LISTEN      -  
    

    任何人都可以帮忙解决这个问题......

3 个答案:

答案 0 :(得分:0)

您是否尝试使用" 127.0.0.1"而不是" localhost"?

答案 1 :(得分:0)

您可能尝试使用错误的端口连接到MySQL。要找出MySQL正在侦听的端口,您可以这样做:

Windows (来自MySQL):
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

<强>的Unix
netstat -tln

确定正确的端口(默认为3306)后,可以在尝试从节点连接时显式指定端口:

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'me',
  password : 'secret',
  port: 3306
});

答案 2 :(得分:0)

我终于能够解决问题: - )

  1. 我使用sudo su
  2. 以root身份登录
  3. 已编辑subl /etc/mysql/my.cnf&amp;将bind-address替换为我的IP4地址
  4. 运行:service mysql restart
  5. 最后它给了我结果:

    mysql stop/waiting
    mysql start/running, process 12210
    

    现在我可以使用外部来源的IP4地址成功登录。

    谢谢大家: - )