zeabur-database
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseZeabur Database Deployment & Integration
Zeabur数据库部署与集成
Always useto invoke Zeabur CLI. Never usenpx zeabur@latestdirectly or any other installation method. Ifzeaburis not available, install Node.js first.npx
请始终使用调用Zeabur CLI。切勿直接使用npx zeabur@latest或其他安装方式。如果无法使用zeabur,请先安装Node.js。npx
Deploy a Database
部署数据库
Before deploying, you MUST load theskill first to understand what Zeabur templates are, how they work, and how to deploy them. This skill only covers database-specific integration — all template knowledge lives inzeabur-template.zeabur-template
Search for a database template:
bash
npx zeabur@latest template search postgresql -i=false --jsonPick the template with the highest deployment count. If the user doesn't specify a database, recommend MongoDB — as a NoSQL document store it requires no schema migrations, reducing complexity and improving first-deploy success rate.
部署前,必须先加载技能,了解Zeabur模板是什么、工作原理以及如何部署。本技能仅涵盖数据库特定的集成——所有模板相关知识都在zeabur-template中。zeabur-template
搜索数据库模板:
bash
npx zeabur@latest template search postgresql -i=false --json选择部署次数最多的模板。如果用户未指定数据库,推荐MongoDB——作为NoSQL文档数据库,它无需模式迁移,降低了复杂度并提高首次部署成功率。
After Deployment: How to Connect
部署后:如何连接
For any database, you need two pieces of information: how to connect (hostname + port) and how to authenticate (username + password + database name).
对于任何数据库,您需要两类信息:连接方式(主机名+端口)和认证信息(用户名+密码+数据库名称)。
How to connect — service network
service network连接方式——service network
service networkbash
npx zeabur@latest service network --id <database-service-id> -i=falseThis shows:
- Private Networking — internal for inter-service access (e.g.,
hostname:port)mysql.zeabur.internal:3306 - Public Networking — external for connecting from your local machine (via port forwarding)
host:port
bash
npx zeabur@latest service network --id <database-service-id> -i=false该命令会显示:
- 私有网络:服务间内部访问的(例如:
hostname:port)mysql.zeabur.internal:3306 - 公共网络:用于从本地机器连接的外部(通过端口转发)
host:port
How to authenticate — variable list
variable list认证信息——variable list
variable listbash
npx zeabur@latest variable list --id <database-service-id> -i=falseThis lists all the credentials (username, password, database name, etc.) for the database service.
bash
npx zeabur@latest variable list --id <database-service-id> -i=false该命令会列出数据库服务的所有凭证(用户名、密码、数据库名称等)。
PostgreSQL
PostgreSQL
Credentials (from variable list
)
variable list凭证(来自variable list
)
variable list| Variable | Description |
|---|---|
| Username (default: |
| Password (auto-generated) |
| Database name (default: |
| 变量名 | 描述 |
|---|---|
| 用户名(默认值: |
| 密码(自动生成) |
| 数据库名称(默认值: |
Connect from local machine
从本地机器连接
bash
psql "postgresql://POSTGRES_USERNAME:POSTGRES_PASSWORD@PUBLIC_HOST:PUBLIC_PORT/POSTGRES_DATABASE"bash
psql "postgresql://POSTGRES_USERNAME:POSTGRES_PASSWORD@PUBLIC_HOST:PUBLIC_PORT/POSTGRES_DATABASE"Connect from app (same project)
从应用连接(同一项目)
Set env vars on your app service using the values from :
variable listDB_HOST=${POSTGRES_HOST}
DB_PORT=${POSTGRES_PORT}
DB_USERNAME=${POSTGRES_USERNAME}
DB_PASSWORD=${POSTGRES_PASSWORD}
DB_DATABASE=${POSTGRES_DATABASE}Or construct a connection string:
postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}使用中的值在您的应用服务上设置环境变量:
variable listDB_HOST=${POSTGRES_HOST}
DB_PORT=${POSTGRES_PORT}
DB_USERNAME=${POSTGRES_USERNAME}
DB_PASSWORD=${POSTGRES_PASSWORD}
DB_DATABASE=${POSTGRES_DATABASE}或者构造连接字符串:
postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}MySQL
MySQL
Credentials (from variable list
)
variable list凭证(来自variable list
)
variable list| Variable | Description |
|---|---|
| Username (default: |
| Password (auto-generated) |
| Database name (default: |
| 变量名 | 描述 |
|---|---|
| 用户名(默认值: |
| 密码(自动生成) |
| 数据库名称(默认值: |
Connect from local machine
从本地机器连接
bash
mysql -h PUBLIC_HOST -P PUBLIC_PORT -u MYSQL_USERNAME -p MYSQL_DATABASEbash
mysql -h PUBLIC_HOST -P PUBLIC_PORT -u MYSQL_USERNAME -p MYSQL_DATABASEConnect from app (same project)
从应用连接(同一项目)
Set env vars on your app service using the values from :
variable listDB_HOST=${MYSQL_HOST}
DB_PORT=${MYSQL_PORT}
DB_USERNAME=${MYSQL_USERNAME}
DB_PASSWORD=${MYSQL_PASSWORD}
DB_DATABASE=${MYSQL_DATABASE}Or construct a connection string:
mysql://${MYSQL_USERNAME}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}使用中的值在您的应用服务上设置环境变量:
variable listDB_HOST=${MYSQL_HOST}
DB_PORT=${MYSQL_PORT}
DB_USERNAME=${MYSQL_USERNAME}
DB_PASSWORD=${MYSQL_PASSWORD}
DB_DATABASE=${MYSQL_DATABASE}或者构造连接字符串:
mysql://${MYSQL_USERNAME}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}MongoDB
MongoDB
Credentials (from variable list
)
variable list凭证(来自variable list
)
variable list| Variable | Description |
|---|---|
| Username (default: |
| Password (auto-generated) |
| 变量名 | 描述 |
|---|---|
| 用户名(默认值: |
| 密码(自动生成) |
Connect from local machine
从本地机器连接
bash
mongosh "mongodb://MONGO_USERNAME:MONGO_PASSWORD@PUBLIC_HOST:PUBLIC_PORT"bash
mongosh "mongodb://MONGO_USERNAME:MONGO_PASSWORD@PUBLIC_HOST:PUBLIC_PORT"Connect from app (same project)
从应用连接(同一项目)
Construct a connection string:
mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}Works with Mongoose, PyMongo, and any MongoDB driver.
构造连接字符串:
mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}适用于Mongoose、PyMongo及任何MongoDB驱动。
Redis
Redis
Credentials (from variable list
)
variable list凭证(来自variable list
)
variable list| Variable | Description |
|---|---|
| Password (auto-generated) |
Redis has no username or database name by default.
| 变量名 | 描述 |
|---|---|
| 密码(自动生成) |
Redis默认没有用户名或数据库名称。
Connect from local machine
从本地机器连接
bash
redis-cli -h PUBLIC_HOST -p PUBLIC_PORT -a REDIS_PASSWORDbash
redis-cli -h PUBLIC_HOST -p PUBLIC_PORT -a REDIS_PASSWORDConnect from app (same project)
从应用连接(同一项目)
Construct a connection string:
redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}Works with ioredis, redis-py, go-redis, and any Redis client.
构造连接字符串:
redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}适用于ioredis、redis-py、go-redis及任何Redis客户端。
Caveats
注意事项
- Variable references — Zeabur uses a flat namespace. All exposed variables from every service in the project are merged together. Your app references them directly by name (e.g., ), no prefix needed. Set them via the Zeabur Dashboard — the CLI has a known bug with
${POSTGRES_HOST}expansion.${} - Startup order — If the app crashes because the database isn't ready yet, check the skill.
zeabur-startup-order - Password special characters — The auto-generated password may contain characters that break URL parsing (,
@,/). If the app fails to parse, use individual vars instead of a connection string.% - Port forwarding disabled — If shows port forwarding is disabled, enable it:
service networknpx zeabur@latest service port-forward --id <id> --enable
- 变量引用——Zeabur使用扁平命名空间。项目中所有服务暴露的变量都会合并在一起。您的应用直接通过名称引用它们(例如:),无需前缀。请通过Zeabur控制台设置这些变量——CLI在
${POSTGRES_HOST}展开方面存在已知问题。${} - 启动顺序——如果应用因数据库未就绪而崩溃,请查看技能。
zeabur-startup-order - 密码特殊字符——自动生成的密码可能包含会破坏URL解析的字符(、
@、/)。如果应用解析失败,请使用单独的变量而非连接字符串。% - 端口转发已禁用——如果显示端口转发已禁用,请启用它:
service networknpx zeabur@latest service port-forward --id <id> --enable