Frequently Asked Questions
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
Usage-Related Questions
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:
- Log in to the CloudBase Platform
- Go to the database management page of the corresponding environment
- Locate the MySQL database instance
- 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