微信云托管的mysql数据库为什么在小程序中不能用内网IP连接?

小程序 文章 2022-04-20 20:20 0 全屏看文

微信云托管的mysql数据库为什么在小程序中不能用内网IP连接?Why can't the mysql database hosted by WeChat cloud be connected with the intranet IP in the applet?

微信云托管的mysql数据库为什么在小程序中不能用内网IP连接?

我在小程序中创建了一个云函数,调用云托管mysql数据库, 使用微信托管的内网IP不能,换为外网IP则好用。

下面是云函数的代码:

const cloud = require('wx-server-sdk')

const mysql = require('mysql2/promise')

cloud.init({

  env: cloud.DYNAMIC_CURRENT_ENV,//云开发环境的初始化

})

exports.main = async(event, context) => {

  context.callbackWaitsForEmptyEventLoop = false

  var sql = event.sql;

  try {

    const connection = await mysql.createConnection({

      host: event.host, //使用微信托管的内网IP不能,换为外网IP则好用。

      database: event.database,

      user: event.user,

      password: event.password,

      port:event.port,  

       })

    const [rows, fields] = await connection.execute(sql)

    return rows;

  } catch (err) {

    console.log("链接错误", err)

    return err

  }

}

I created a cloud function in the applet to call the cloud hosted MySQL database. The intranet IP hosted by wechat cannot be used, but it is easy to use the external IP. The following is the code of the cloud function: const cloud = require ('wx server SDK ') const MySQL = require ('mysql2 / promise') cloud Init ({env: cloud.dynamic_current_env, / / initialization of cloud development environment}) exports Main = async (event, context) = > {context. Callbackwaitsforemptyeventloop = false var SQL = event. SQL; try {const connection = await mysql. Createconnection ({host: event. Host, / / the intranet IP hosted by wechat cannot be used, but it is easy to use the external IP. Database: event. Database, user: event. User, password: event. Password, port: event. Port,}) const [rows, fields] = await connection execute(sql) return rows; } Catch (ERR) {console.log ("link error", ERR) return err}}

回答:

Vxwenweny:什么意思我更新不了
拾忆:

云函数和云托管不在一个内网,云托管有自己单独的内网数据库。

Mr.Zhao:

云函数和微信云托管不是一个内网

-EOF-