Mac OSX上的MariaDB和node.js

时间:2016-10-04 20:41:05

标签: node.js macos mariadb

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

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

将ECONNREFUSED连接到我的系统的IP地址,然后连接端口3306

这看起来像权限问题,但我对MAC很新,不知道如何解决问题。在node.js中运行的脚本可以在我的Windows系统上运行。

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

MAC OSX正在运行最新的os x sierra,mariadb是版本15.1发行版10.1.17 for osx10.12 x64。 node是版本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地址有关,我将服务器地址硬编码为&#34; localhost&#34;并且它有效,但分配给系统的I / P有什么问题?

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

1 个答案:

答案 0 :(得分:1)

您无法通过IP地址进行连接的原因记录在案here

  

MariaDB软件包默认将MariaDB绑定到127.0.0.1(环回IP地址)...

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