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

小程序 文章 2022-04-20 20:20 1063 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群

相关文章
小程序的token怎么获取?
微信小程序wxss可以动态的用js的值吗?怎么传?
开发者本人想长期接收小程序订阅消息,主要用于及时接受用户反馈,怎么实现?
订阅消息,subscribeMessage.send调用报47001?
之前有个小程序,又开发了一个新的小程序,新开发的小程序可以用之前的名称吗?
随便看看
微信公众号免300认证教程 5077
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 4391
小程序广告组件通过审核,但是小程序内没有显示广告? 4362
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8388
问题? 7602
如何快速搭建抽奖助手小程序(无需代码知识) 5178
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6346
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5754
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5417
如何解决渲染层网络错误Failed to load media? 16671