Deploy MySQL
Zeabur provides a one-click deployment feature for MySQL service, allowing you to quickly deploy a MySQL database on Zeabur.
Deploying a MySQL service
To deploy this service, you will need to create a project first if you haven’t done so. You can follow this document to create your project.
In your project, click Deploy New Service and select Deploy MySQL Service from Deploy Other Services.
After clicking Deploy, Zeabur will automatically deploy the MySQL service for you.
Environment Variables
After deploying the MySQL service, Zeabur will automatically inject relevant environment variables into other services.
MYSQL_HOST
MYSQL_PORT
MYSQL_USERNAME
MYSQL_PASSWORD
Sometimes, we can create a DATABASE_URL
to replace the above environment variables, for example:
mysql://<MYSQL_USERNAME>:<MYSQL_PASSWORD>@<MYSQL_HOST>:<MYSQL_PORT>/<DATABASE_NAME>
Here, <DATABASE_NAME>
is the name of the database that you added yourself.
Adding a Database
By default, the username and database name in Zeabur’s MySQL are both root
. Here, we need to add the first database ourselves, which can be done in the following ways.
MySQL Workbench
MySQL Workbench is a database visualization tool that can be used to design, maintain, and manage MySQL databases. It has an easy-to-use interface and can be used to query, back up and restore databases, as well as diagnose and optimize database performance.
You can use MySQL Workbench to connect to the MySQL database deployed on Zeabur.
First, you need to click the button next to MySQL connections to add a connection.
Then, click Store in Keychain to save the password.
Next, you can execute SQL syntax in the Query Editor to add a database. Enter:
CREATE DATABASE <DATABASE_NAME>
mysqlsh
mysqlsh is an advanced command-line tool for managing and operating MySQL databases. It supports multiple programming languages, including JavaScript, Python, and SQL, allowing users to write scripts in their preferred languages.
First, you can connect to the MySQL database deployed on Zeabur using the following command:
mysqlsh --uri mysql://root:<MYSQL_PASSWORD>@<MYSQL_HOST>:<MYSQL_PORT>
Then, switch to SQL mode:
\sql
Finally, you can execute SQL syntax to add a database. Enter:
create database <DATABASE_NAME>;