Skip to main content

Connect Your Own MySQL

You can connect your own MySQL database to the CloudBase platform, reuse existing database resources, and reduce data migration costs.

After connecting your own database, you can:

  • Seamless Integration: Directly manage data in your existing database without data migration
  • Data Models: Quickly generate data models based on existing tables for automated data management
  • SDK Support: Unified access using CloudBase Web SDK / Node SDK / Mini Program SDK
  • Secure and Controllable: Data remains in your database with full control over data security

Prerequisites

Before configuring your own MySQL database connection, please ensure:

Check ItemRequirements
Network AccessDatabase has public network access capability
User PermissionsDedicated database user account has been created with table operation permissions
Firewall ConfigurationDatabase firewall has opened the corresponding port (default 3306)
IP WhitelistCloudBase service IP whitelist has been configured (see end of document)

Create Connection Configuration

1. Access Configuration Page

Visit CloudBase Platform/MySQL Database, click the "Add" button at the top

MySQL Database Add Page

2. Fill in Connection Information

ParameterDescriptionRequired
Database TypeSelect "MySQL" or "SQLServer" (SQLServer requires ticket application)Yes
Configuration NameCustom name for identifying this connection in the platformYes
Configuration IdentifierEnglish identifier for specifying the connection in SDK (e.g., my-database)Yes
Access MethodSelect "Own Database" or "Tencent Cloud Database"Yes
Host AddressPublic IP address or domain name of the MySQL databaseYes
PortMySQL service port (default 3306)Yes
Database NameTarget database name to connectYes
UsernameDatabase connection usernameYes
PasswordDatabase connection passwordYes
Connection ParametersAdditional MySQL connection parameters (e.g., charset=utf8mb4)No
TimeoutConnection and query timeout (unit: seconds)No
Note

To connect a "SQLServer Database", please contact Tencent architect or submit a ticket for application.

Usage Methods

After connecting your own MySQL database, you can operate data in the following two ways.

Method 1: Direct Database Table Operations

Perform CRUD operations directly through SDK

// Import SDK
const { init } = require("@cloudbase/wx-cloud-client-sdk");

// Specify CloudBase environment ID
wx.cloud.init({
env: "your-env-id", // Replace with your environment ID
});

const client = init(wx.cloud);

// Connect to your own database instance
const db = client.rdb({
instance: "my-database", // Configuration identifier (identifier filled when creating the connection)
database: "test", // Database name
});

// Query data
const { data, error } = await db
.from("users")
.select("*")
.eq("status", "active");

if (error) {
console.error("Query failed:", error);
} else {
console.log("Query result:", data);
}
Parameter Description
  • instance: The "Configuration Identifier" filled when creating the connection configuration
  • database: Target database name
  • For query syntax, please refer to: Web SDK or Node SDK

Method 2: Using Data Models

Suitable for scenarios requiring structured data management, automatic validation, relational queries, etc.

1. Create Data Model

Visit CloudBase Platform/MySQL Database/Connection Management, click "Data Model" on the corresponding connection configuration

CloudBase Platform-MySQL Database-Connection Configuration Click Data Model Page

Select an existing data table, and the system will automatically generate the corresponding data model.

2. Operate Data Models

// Import SDK
const { init } = require("@cloudbase/wx-cloud-client-sdk");

wx.cloud.init({
env: "your-env-id", // Replace with your environment ID
});

const client = init(wx.cloud);
const models = client.models;

// Create data (assuming the todos model has been created)
const { data, error } = await models.todos.create({
data: {
title: "Learn CloudBase",
completed: false,
},
});

// Query data
const todos = await models.todos.findMany({
where: {
completed: false,
},
orderBy: {
createdAt: "desc",
},
});

console.log(todos);
Tip

For detailed usage, please refer to Data Model Documentation

IP Whitelist Configuration

To ensure database security, please add the following CloudBase service IP addresses to your MySQL database whitelist:

175.24.211.44
175.24.212.162
175.24.213.48
175.24.214.104
175.24.214.93
49.234.25.245
49.234.27.58
49.234.3.160
49.234.34.31
49.234.35.33
Important
  • All IP addresses must be added to ensure normal service operation
  • Whitelist configuration methods vary among cloud service providers, please refer to the corresponding database management documentation

FAQ

How to troubleshoot connection failures?

Troubleshoot step by step:

  1. Network Connectivity: Confirm the database is accessible via public network
  2. Firewall Configuration: Check if the database port is open
  3. IP Whitelist: Confirm all CloudBase service IPs have been added
  4. Connection Parameters: Check if host address, port, database name, username, and password are correct

Does it support intranet databases?

Currently only databases with public network access capability are supported. To connect to intranet databases, consider:

  • Access via public proxy provided by cloud service provider
  • Use VPN or dedicated line to connect networks
  • Use Tencent Cloud Database (supports direct intranet connection)

Will data be synchronized to CloudBase?

No. After connecting your own database:

  • Data Storage: All data remains in your database
  • Access Method: CloudBase SDK directly connects to your database for operations
  • Data Control: You have full control over data storage and backup