MySQL

This document provides a detailed guide on how to install and use the MySQL database within the Clacky development environment. Please follow the steps below.

Installing the Database

mysql

  1. Open the Services window: Navigate to Thread, select Services in the CDE Tools, and click to open.

  2. Choose the database type: From the database options, select MySQL.

  3. 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.

Using a Client Tool

  1. Open a MySQL client tool (e.g., MySQL Workbench).
  2. Create a new connection and enter the following information (example):
    • Hostname: mysql.develop.clackypaas.com
    • Port: 3306
    • Username: root
    • Password: dGFuZLra
  3. Click Test Connection to verify the connection.

The parameters listed are illustrative. Please substitute them with the actual parameters given post-installation.

Connecting via Terminal

You can use the following command to connect to the MySQL database in the terminal:

mysql -h 30.0.2.135 -P 32795 -u root -p

Enter the password ‘dGFuZLra’ to log in

The parameters in the above command are just examples, please replace them with real parameters when connecting.

Using the Database in the Project

In the project, you can use environment variables to access the database connection information.

  • MYSQL_HOST
  • MYSQL_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_HOST,
  port: process.env.MYSQL_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.