Skip to content

MySQL Service (mysql)

SidePro's Managed MySQL Service (mysql) can be deployed and used by your application for SQL-compatible database functionality.

When a MySQL service is bound to an application (reference documentation for CLI and UI), a series of environment variables will automatically be exported for your application to consume. The environment variables are listed below:

  • MYSQL_HOSTNAME: The hostname or IP address of the MySQL server.
  • MYSQL_USERNAME: The username required for authentication and connection to the MySQL database.
  • MYSQL_PASSWORD: The password corresponding to the MySQL username.
  • MYSQL_PORT: The port number on which the MySQL server is listening.
  • MYSQL_DB_NAME: The name of the specific database within the MySQL server.
  • MYSQL_DATABASE_URL: The full connection URL for MySQL, formatted as mysql://<MYSQL_USERNAME>:<MYSQL_PASSWORD>@<MYSQL_HOSTNAME>:<MYSQL_PORT>/<MYSQL_DB_NAME>. This URL includes all necessary details for connection.

Note

For most use-cases, utilizing the MYSQL_DATABASE_URL should be sufficient for usage.

Connecting to the MySQL Service

To connect directly to your MySQL service for local development, debugging, or using GUI tools, you can use the sidepro service port-forward command. For detailed information about port forwarding, see the Port Forwarding Guide.

Using Port Forwarding

  1. First, find your MySQL service name:

    $ sidepro service list
    Namespace: your-namespace
    Fetching services... done
    
    Services:
    
      ┌─────────────────────────────────────┬───────────────────────────┬─────────────────┬─────────┬──────────┬──────────────────────┐
      │                NAME                 │          CREATED          │ CATALOG SERVICE │ VERSION │  STATUS  │     APPLICATIONS     │
      ├─────────────────────────────────────┼───────────────────────────┼─────────────────┼─────────┼──────────┼──────────────────────┤
      │ my-db                              │ 2025-03-10, 8:42:15 a.m.  │ mysql           │ 8.0.31  │ deployed │ my-app              │
      └─────────────────────────────────────┴───────────────────────────┴─────────────────┴─────────┴──────────┴──────────────────────┘
    
  2. Start port forwarding to your MySQL service (using the standard MySQL port 3306):

    $ sidepro service port-forward my-db 3306
    Namespace: your-namespace
    Forwarding from localhost:3306 -> my-db. Use CTRL+C to stop forwarding.
    
  3. In a new terminal, you can now connect to your MySQL instance using various methods:

    Using mysql CLI:

    $ mysql -h localhost -P 3306 -u root -p${MYSQL_PASSWORD} ${MYSQL_DB_NAME}
    
    Or using the connection URL:
    $ mysql --url="mysql://root:${MYSQL_PASSWORD}@localhost:3306/${MYSQL_DB_NAME}"
    

    Using MySQL Workbench: 1. Open MySQL Workbench 2. Create New Connection 3. Fill in the connection details: - Connection Method: Standard (TCP/IP) - Hostname: localhost - Port: 3306 - Username: root - Password: (your MYSQL_PASSWORD) - Default Schema: (your MYSQL_DB_NAME)

    Using Node.js with mysql2:

    const mysql = require('mysql2/promise');
    
    const connection = await mysql.createConnection({
      host: 'localhost',
      port: 3306,
      user: 'root',
      password: process.env.MYSQL_PASSWORD,
      database: process.env.MYSQL_DB_NAME
    });
    

Tip

The MySQL root password can be obtained using:

$ sidepro service show my-db | grep mysql-root-password

Note

  • For local development, you'll need to install appropriate MySQL tools:
  • mysql: The official MySQL command-line client
  • MySQL Workbench: The official MySQL GUI client
  • Keep the port-forwarding terminal window open while working with your MySQL instance
  • Remember to use CTRL+C to stop port forwarding when you're done -->