FAQ
Billing Related Questions
What are the differences between MySQL database in WeChat Cloud Hosting and MySQL database in CloudBase?
MySQL database in WeChat Cloud Hosting environment:
- Uses pay-as-you-go billing method
- Billing includes computing resource usage and storage capacity
- Usage generated on the same day will be settled and charged in the early morning of the next day
MySQL database in CloudBase:
- Billing also includes computing resource usage and storage capacity
- Charging method follows priority: Package > Resource Pack > Pay-as-you-go for excess
Usage Related Questions
Slow response or errors when accessing MySQL data model?
Problem Cause:
MySQL database supports auto-pause feature. If not accessed for 30 minutes, it will automatically pause to reduce computing resource consumption. When accessed again, the service needs to be started, which may result in longer response time for the first request.
Solution:
Disable the auto-pause feature in the console to avoid this issue.
Operation Steps:
- Go to CloudBase Platform/MySQL Database/Database Settings
- Disable the "Auto Pause" feature
How to support transactions in MySQL
CloudBase MySQL currently does not support transaction operations. If you need to use transaction functionality, it is recommended to directly call MySQL native API through Cloud Run to implement it.
💡 Note: When using native MySQL API, you need to manage database connections and transaction states yourself.
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();
// Execute 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();
}
};
Query conditions are correct but result is empty
When using database queries, if an empty result is returned, there are usually two situations:
- No data matches the query conditions
- Data is filtered by permission control
Troubleshooting Methods
Confirm data existence
- Check directly in the CloudBase console whether the target data exists in the collection
- Verify if the creation time and field values of the data meet expectations
Check permission configuration
- Check if the basic permission settings of the collection allow the current user to read
- Database queries use the
_openidfield as the basis for data ownership determination - If security rules are used, verify that the rule expressions are correct
- Confirm that the query conditions include the necessary fields required by security rules
Verify query conditions
- Simplify query conditions and gradually troubleshoot which condition causes the empty result
- Check if field names, data types, and query syntax are correct