ApsaraDB for MySQL
Use the ApsaraDB for MySQL node to insert, delete, update, and query data in an ApsaraDB for MySQL table.
Prerequisites
-
You have purchased an ApsaraDB for MySQL instance. For more information, visit the ApsaraDB for MySQL product page.
-
You have created a database and a table. For more information, see ApsaraDB for MySQL databases.
-
You have added
0.0.0.0/0to the IP whitelist of your ApsaraDB for MySQL instance. For more information, see Configure an IP whitelist.NoteThe IP address range
0.0.0.0/0allows access from any device. Use this with caution. -
You have created a project and a business service. For more information, see Projects and Create a business service.
Node configuration
In the business logic editor, add an ApsaraDB for MySQL node from the Nodes panel to your business flow to configure it.
|
Parameter |
Description |
|
node name |
The name of the node. The name can contain Chinese characters, letters, digits, and underscores (_). It must be 30 characters or less. |
|
username |
The username for your ApsaraDB for MySQL instance account. You can find this on the account management page of the instance in the RDS console. For more information about ApsaraDB for MySQL, see (Deprecated) Usage flow. |
|
password |
The password for the ApsaraDB for MySQL instance account. |
|
endpoint |
The public endpoint of the instance. You can find the public endpoint on the database connection page of the instance in the RDS console. Note
If your IoT Studio project and ApsaraDB for MySQL instance are in the same Alibaba Cloud account, region, and VPC, you can also use the internal endpoint to connect to the database. |
|
database name |
The name of the database. You can find it on the database management page of the instance in the RDS console. |
|
port number |
The public port number of the instance. You can find the public port number on the database connection page of the instance in the RDS console. |
|
operation type |
The database operation to perform. The available options are:
|
|
parameters |
The parameters required for the selected operation type. For details, see Parameters below. Note
|
Parameters
You can use variables in the parameters. IoT Studio has the following built-in global variables:
- payload: The output from the previous node. You can access data for a specific key using
payload.key_in_object.For example,
payload.productKeyaccesses the value from the previous node's output{productKey: 'value'}. - query: The data from the entry node, such as the input parameters of an HTTP request node or the device data from a device trigger node. You can access specific data using
query.parameter_name.For example,
query.deviceNameaccesses the value of the input parameter deviceName in an API request node. - node: The output from a specific node (
node.node_ID). You can access data for a specific key usingnode.node_ID.key_in_output_object.For example,
node.node_39***0.pageNumaccesses the value of pageNum from the output of the node_39***0 node.
The following list describes the parameter structure and provides examples for each operation type.
-
insert
{ "table": "", // The name of the table "rows": [{}] // The data to insert }Example
{ "table": "base_info", "rows": [ { "id": "{{payload.id}}", "user": "{{payload.user}}", "ext": "{{payload.ext}}", "msg": "{{payload.msg}}" } ] } -
query
{ "table": "", // The name of the table "condition": { // The query conditions "where": {}, // The WHERE clause to filter results "columns": [], // The columns to retrieve "orders": [], // The sorting order "limit": 10, // The page size "offset": 1 // The page number } }Example
{ "table": "base_info", "condition": { "where": {"id": "{{query.id}}"}, "columns": ["id", "user", "ext"], "orders": [["id", "desc"]] } } -
delete
{ "table": "", // The name of the table "condition": { // The deletion criteria } }Example
{ "table": "base_info", "condition": { "id": "{{node.node_78***40.id}}" } } -
update
{ "table": "", // The name of the table "row": {}, // The key-value pairs to update "condition": { // The update conditions "where": {}, // The WHERE clause to identify rows to update "columns": [] // The columns to update } }Example
{ "table": "base_info", "row": {"user": "xxx", "ext": "yyy"}, "condition": { "where": {"id": "{{query.id}}"}, "columns": ["user", "ext"] } }
Node output
The node returns the result of the ApsaraDB for MySQL operation.