MariaDB 和 node.js 在 Mac OSX

MariaDB and node.js on Mac OSX

我有一个 MAC 安装了 MariaDB 和 运行。我安装了两个应用程序,"Sequel Pro",运行 本机在 MAC 上,它们可以工作并且我可以连接到数据库。我在wine下也有HeidiSQL 运行,也可以连接浏览数据库

我也安装了节点,但是当我尝试连接到数据库时,我无法连接到数据库,我收到的消息是:

连接 ECONNREFUSED 然后连接我系统的 IP 地址和端口 3306

这看起来像是一个权限问题,但我对 MAC 还很陌生,不确定如何解决这个问题。 node.js 中的脚本 运行 在我的 Windows 系统上工作。

我知道该用户存在且有效,与我使用 SQL 应用程序连接时相同。

MAC OSX 是 运行 最新的 os x sierra,mariadb 是版本 15.1 distribution 10.1.17 for osx10.12 x64 .节点是版本 4.6.0

我的连接例程:

    function mariaDBconnectPrimtive(intIdx, cbRoutine, objParams) {
      try{
        if ( !(mysql && mysql.createPool) ) {
          throw( "Cannot create mysql pool!" );
        }
        var pool;

        if ( intIdx == 1 ) {
          pool = mysqlBusDevPool; 
        } else {
          pool = mysqlPool; 
        }
        if ( pool == undefined ) {
           console.log("strServerHost: " + strServerHost);
           pool = mysql.createPool({host:strServerHost
                          ,port:"3306"
                      ,database:"dbname"
                          ,user:"usrname"
                      ,password:"password"
                      ,timezone:"utc"
            ,multipleStatements:true
                           ,max:1000
                           ,min:1
             ,idleTimeoutMillis:defs.QUERY_TIMEOUT});      
        }
        if ( pool && pool.getConnection ) {  
          pool.getConnection(function(errsts, conn) {
              var resp = {};

              if ( errsts ) {
                resp['error'] = errsts;
                eh.msg({file:strThisFile
                     ,method:"mariaDBconnectPrimtive"
                         ,ex:errsts});
                return;        
              }
              resp['state'] = "connected";

              if ( cbRoutine ) {        
                cbRoutine(conn, resp, objParams);

                if ( conn != undefined ) {
                  conn.release();
                }
             }
          });
        }
        if ( intIdx == 1 ) {
          mysqlBusDevPool = pool; 
        } else {
          mysqlPool = pool; 
        }
      } catch(ex) {
        eh.msg({file:strThisFile
             ,method:"mariaDBconnectPrimtive"
                 ,ex:ex});
      }    
    };

节点开始获取系统IP时执行的代码:

    os = require("os");
    var objNIs = os.networkInterfaces();        
    for( var strName in objNIs ) {
       var aryIFace = objNIs[strName];
       for( var i=0; i<aryIFace.length; i++ ) {
          var objNI = aryIFace[i];

          if ( objNI['internal'] == false && "IPv4".match(objNI['family']) ) { 
            strServerHost = objNI['address'];
            break; 
          }      
        }
        if ( strServerHost !== undefined ) {
          break;
        }
      }

这似乎与返回的 IP 地址有关,我将服务器地址硬编码为 "localhost" 并且它有效,但是分配的 I/P 有什么问题到系统?

我在 mariadb 中创建了一个用户,有权访问原始 I/P 但这没有帮助。

无法通过 IP 地址连接的原因已记录在案 here:

MariaDB packages bind MariaDB to 127.0.0.1 (the loopback IP address) by default...

这意味着它只能通过环回接口访问,而不是任何其他可能允许外部 IP 流量的接口(比如与您的代码解析到的 IP 地址关联的接口)。