Services
ClackyAI cloud development environment has built-in database services including MySQL, PostgreSQL, Redis, MongoDB, etc. ClackyAI will automatically select, install and use database services for your project during project initialization.
This document provides a detailed guide on how to install and use a new database within the Clacky development environment. Please follow the steps below.
Installing the Database
-
Open the Services window: Navigate to Thread, select Services in the CDE Tools, and click to open.
-
Choose the database type: From the database options, select a database, such as MySQL.
-
Click Install: Click the Install button in the upper right corner to begin installing the MySQL database.
Connecting to the Database
After installation, connection information will be displayed. You can connect to the newly installed database using an external MySQL client with the external address, or directly through the Thread terminal.
Connecting via Terminal
You can use the following command to connect to the MySQL database in the Thread terminal:
mysql -h 127.0.0.1 -P 3306 -u root -pZYIQkJaE
The parameters in the above command are just examples, please replace them with real parameters when connecting.
Using a Client Tool
- Open a MySQL client tool (e.g., MySQL Workbench).
- Create a new connection and enter the following information (example):
- Hostname: mysql.clackypaas.com
- Port: 3306
- Username: root_AIfwJOWWwVWEEACYruWo
- Password: PtadKeRr
- Click Test Connection to verify the connection.
The parameters listed are illustrative. Please substitute them with the actual parameters given post-installation. Client tools require external access, please enable External Address to allow external network connections and access to the database.
Using the Database in the Project
In the project, you can use environment variables to access the database connection information.
- MYSQL_INNER_HOST
- MYSQL_INNER_PORT
- MYSQL_USER
- MYSQL_PASSWORD
The above environment variables are automatically injected into the main container environment after the database is installed.
Configuration Example
In a Node.js project, you can use the dotenv package to load environment variables:
require('dotenv').config();
const mysql = require('mysql');
const connection = mysql.createConnection({
host: process.env.MYSQL_INNER_HOST,
port: process.env.MYSQL_INNER_PORT,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
});
connection.connect((err) => {
if (err) throw err;
console.log('Connected to MySQL database!');
});
Removing the Database
To delete the database, click the “Remove” button in the Thread CDE Tools - Services. Be aware that once deleted, the data is permanently lost.
Important considerations:
- Ensure you back up all important data before removal.
- You can reinstall at any time after removal, but the data will not be restored.