Skip to main content

Connecting with mysql

This guide explains how to connect to a MySQL database using the mysql command-line tool. It walks through the necessary setup, connection process, and execution of a simple SQL query.

Variables

To connect to a MySQL database, you will need the following individual connection parameters. These are available on the Elestio service overview page:

Variable

Description

Purpose

USER

MySQL username

Identifies the database user.

PASSWORD

MySQL password

Authenticates the user.

HOST

MySQL host address

Endpoint to connect to the database service.

PORT

MySQL port number

Default is usually 3306, unless otherwise configured.

DATABASE

Database name

The specific database you want to connect to.

You can find all of these values in your Elestio project dashboard under the Admin or Database Info section.

Prerequisites

Make sure the MySQL client is installed on your local system. If not, download and install it from:

https://dev.mysql.com/downloads/

Connecting to MySQL

Open your terminal and run the following command to connect to the MySQL database using the values you copied from your Elestio service:

mysql -h HOST -P PORT -u USER -p DATABASE
  • Replace HOST, PORT, USER, and DATABASE with the actual values.

  • After running the command, you will be prompted to enter the PASSWORD.

If the connection is successful, you will see output similar to this:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.34 MySQL Community Server - GPL

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Verifying the Connection

To ensure you’re connected correctly, run the following command in the MySQL prompt:

SELECT VERSION();

You should see output like this:

+-----------+
| version() |
+-----------+
| 8.0.34    |
+-----------+
1 row in set (0.00 sec)

This confirms that your connection to the Elestio-hosted MySQL service is working correctly.