Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Function calculates how to access the MySQL database

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to access the MySQL database by function calculation, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Functional Computing (Function Compute): functional Computing is an event-driven fully managed computing service. Using function calculations, you don't need to purchase and manage infrastructure such as servers, just write and upload code. Function computing prepares computing resources for you, runs tasks flexibly and reliably, and provides functions such as log query, performance monitoring and alarm. With function computing, you can quickly build any type of application and service, and only pay for the resources actually consumed by the task.

Accessing the MySQL database refers to the operation of inserting and querying the database through the TCP protocol by writing code to call the database driver library. Usually, the state of different function instances running in function calculation is not shared, and the structured data can be persisted in the form of database to achieve state sharing. Since the user function runs in the VPC of function calculation, and the user's database runs in the VPC to which the user belongs, accessing the database in the function computing platform will involve cross-VPC access, so let's first introduce its working mechanism.

Working mechanism

Access to IP is not fixed when you run the function, so you cannot access MySQL by setting a whitelist. Based on the principle of minimum permissions, it is not recommended to set all IP (0.0.0.0Univer 0) to the database whitelist in a production environment. Function computing already supports the proprietary network VPC feature. You can enable VPC access for the service where the function resides to access resources in the VPC securely.

You can place MySQL in a secure private network VPC and configure function computing to access resources in VPC. Function computing can securely access your cloud database through VPC.

The workflow for function calculation to access MySQL is shown as follows:

The function calculates the principle of visiting user VPC as follows:

The user's VPC is the user's private network, which requires user authorization to grant the elastic Nic ENI the ability to access the VPC, and insert the ENI into the machine that executes the user function in the FC, so that the function can access the resources in the user's VPC. Function calculation configuration VPC function, please refer to the details.

If the user's VPC resource is not in the current availability zone of the function calculation, you can create a VSwitch in the same availability zone as the function calculation in the user VPC environment, and set this VSwitchID in the VPC configuration of the function calculation service. Due to the intranet interworking between different switches in the same private network, the function calculation can access the resources in the user VPC in other availability zones through the VSwitch.

After the MySQL instance is created successfully, you need to set the whitelist and enter the corresponding instance. Click data Security on the left, select whitelist settings, and set the default in the private network to the configured private network IP segment of the VPC instance or configure the private network IP segment of the switch configured by FC.

Access MySQL database host as the private network address of the instance, and log in to the Aliyun console to view:

Configure public configuration to create a proprietary network VPC

Log into the VPC console.

See VPC to build a proprietary network to create VPC and switches.

Create a security group

Create a new security group in the Security Group console, click create Security Group, set the security group name, select the private network for the network type, and select the private network you just created.

Create a MySQL instance

Create a new RDS instance in the RDS console and click create instance.

Basic configuration choose the configuration you need, there are no special requirements to choose the default configuration.

Select the proprietary network for the network type, and select the VPC and switch that you have created.

Select the storage space and purchase amount you need and buy it now. That is, the RDS instance is created successfully.

After the instance is created successfully, you need to set the whitelist and enter the corresponding instance. Click data Security on the left, select whitelist settings, and set the default in the private network to the configured private IP segment of the VPC instance or configure the private IP segment of the switch configured by FC.

After the whitelist is set successfully, click Database Management on the left, click create Database, and set the database name.

Create a new account to access the database. Click on the left account management, fill in the database account, authorization database, login password. You can log in to the database through this account.

On the instance details page, click the upper right corner to log in to the database and use the account you just created to log in to the database. (if you do not have DMS access, the console will pop up the authorization page and authorize according to the prompts.)

After logging in to the DMS system, select the database in the upper left corner, and you can create tables, insert data, and so on.

So far, you have successfully created VPC, security group, and RDS.

Function calculates configuration VPC

Note: the area where the function calculation service is located is the same as that of the resources created in the public configuration.

Create a service in the function calculation console.

For the steps to create a service, please refer to the article about the addition, deletion, modification and query of the service.

In the "proprietary Network configuration" option, select the VPC network, switch and security group that you created in step 1.

In the "permission configuration" option, select "New role", click "Click Authorization", and then click "agree to Authorization" on the role Quick creation page.

The operation of this step is to grant the function permission to operate on the ENI. The function calculates the permissions required to access the resources in the VPC. Please refer to the article configuring the function to calculate the access to the resources in the VPC.

Click OK to complete the new service.

Installation module

In the function code, you need to use the third-party module that accesses the MySQL. You need to download the third-party module to the directory where the entry is located, put the third-party module and the entry function in the same folder, and then package and upload them together to the function calculation. Third-party module packaging please refer to the article to install third-party dependencies for the function.

Advantages of using function calculations:

Without the need to purchase and manage infrastructure such as servers, you only need to focus on the development of business logic, which can greatly reduce project delivery time and labor costs

Provide log query, performance monitoring, alarm and other functions for rapid troubleshooting

Operation and maintenance-free, millisecond elastic expansion, rapid bottom expansion to cope with peak pressure, excellent performance

The cost is very competitive

The above content is the function calculation how to access the MySQL database, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report