Skip to main content

FAQ

Metering and Billing FAQs

What is the difference between MySQL databases in WeChat Cloud Hosting and Cloud Development?

MySQL Database in WeChat Cloud Hosting Environment:

Use pay-as-you-go billing

  • Metering includes compute resource usage and storage usage
  • Usage generated on the same day is settled and billed in the early morning of the following day.

MySQL Database in Cloud Development:

  • Metering also includes compute resource usage and storage usage
  • Billing priority: Plan > Resource Pack > Pay-as-you-go for overages

How to troubleshoot slow response when accessing the MySQL data model?

Cause: MySQL databases support the auto-pause feature. If there is no access for 10 minutes, the database will automatically pause to reduce computing resource consumption. When re-accessing, the service needs to be started, which may cause the first request to take longer.

Solution: You can disable the auto-pause feature in the console if you are using a MySQL database to avoid this issue.

Procedures:

  1. Log in to the CloudBase Platform
  2. Go to the database management page of the corresponding environment
  3. Locate the MySQL database instance
  4. Disable the auto-pause feature in the settings

How the MySQL data model supports transactions

The CloudBase MySQL data model currently does not support transactional operations. If you need to use transaction features, it is recommended to directly call MySQL native APIs through CloudBase Run.

💡 Note: When using native MySQL APIs, you need to manage database connections and transaction states manually.

Implementation Example

const mysql = require('mysql2/promise');

exports.main = async () => {
const conn = await mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME
});

try {
await conn.beginTransaction();

// Perform multiple related operations
await conn.query('UPDATE accounts SET balance = balance - 100 WHERE user_id = 1');
await conn.query('UPDATE accounts SET balance = balance + 100 WHERE user_id = 2');

await conn.commit();
return { success: true };
} catch (error) {
await conn.rollback();
return { success: false, error: error.message };
} finally {
conn.end();
}
};

Notes

  • Ensure that the database connection information is correctly configured in the cloud function environment variables
  • Transaction operations should include complete error handling and rollback mechanisms
  • Use parameterized queries to prevent SQL injection
  • Close database connections promptly to avoid connection leaks

Query conditions are correct but results are empty

When using database queries, if empty results are returned, there are usually two situations:

  1. No data matches the query conditions
  2. Data is filtered by permission control

Troubleshooting Methods

  1. Confirm data existence

    • Check directly in the CloudBase console whether the target data exists in the collection
    • Verify that the creation time and field values of the data meet expectations
  2. Check permission configuration

    • Check whether the basic permission settings of the collection allow the current user to read
    • If using security rules, verify that the rule expressions are correct
    • Confirm that the query conditions include the necessary fields required by security rules
  3. Verify query conditions

    • Simplify query conditions and gradually troubleshoot which condition causes empty results
    • Check whether field names, data types, and query syntax are correct