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

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

AI助手支持GPT4.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-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
微信支付特约商户可以转普通商户吗?怎么转?
getSetting的scope.userInfo一直为true,那如何判断是否授权?
当前小程序暂不支持iOS用户访问,怎么处理?无问题请核实
火星船票怎么申请?
小程序?
随便看看
请问公众号的管理员能设置权限吗? 699
能否生成微信商户的二维码? 542
这种小程序又不是,H5又不像,类似抽奖活动的形式是怎么实现的? 548
能在小程序中直接打开某个app吗? 547
第三方平台 WEB + 小程序的这种需求如何实现? 536
微信红包封面旋转抽取如何制作? 526
request:fail url not in domain list? 446
我该如何实现多人共同在微信小程序一张canvas上画图啊? 540
微信开放平台 登录提示不存在 注册提示已存在? 869
定义多个组件,使用wx:if判断显示隐藏,为什么只有第一个组件触发了onshow? 570