# How to Connect

# Connecting with Node.js

This guide explains how to establish a connection between a Node.js application and a MySQL database using the `<span class="s3">mysql2</span>` package. It walks through the necessary setup, configuration, and execution of a simple SQL query.

## **Variables**

Certain parameters must be provided to establish a successful connection to a MySQL database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="border-collapse: collapse; border-color: rgb(0, 0, 0); width: 100%; height: 262.766px;"><thead><tr style="height: 29.7969px;"><th style="border-color: rgb(0, 0, 0); width: 10.0102%; height: 29.7969px;">**Variable**

</th><th style="border-color: rgb(0, 0, 0); width: 40.4069%; height: 29.7969px;">**Description**

</th><th style="border-color: rgb(0, 0, 0); width: 49.5828%; height: 29.7969px;">**Purpose**

</th></tr></thead><tbody><tr style="height: 46.5938px;"><td style="border-color: rgb(0, 0, 0); width: 10.0102%; height: 46.5938px;">`USER`

</td><td style="border-color: rgb(0, 0, 0); width: 40.4069%; height: 46.5938px;">MySQL username, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%; height: 46.5938px;">Identifies the database user who has permission to access the MySQL database.

</td></tr><tr style="height: 46.5938px;"><td style="border-color: rgb(0, 0, 0); width: 10.0102%; height: 46.5938px;">`PASSWORD`

</td><td style="border-color: rgb(0, 0, 0); width: 40.4069%; height: 46.5938px;">MySQL password, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%; height: 46.5938px;">The authentication key is required for the specified USER to access the database.

</td></tr><tr style="height: 46.5938px;"><td style="border-color: rgb(0, 0, 0); width: 10.0102%; height: 46.5938px;">`HOST`

</td><td style="border-color: rgb(0, 0, 0); width: 40.4069%; height: 46.5938px;">Hostname for MySQL connection, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%; height: 46.5938px;">The address of the server hosting the MySQL database.

</td></tr><tr style="height: 46.5938px;"><td style="border-color: rgb(0, 0, 0); width: 10.0102%; height: 46.5938px;">`PORT`

</td><td style="border-color: rgb(0, 0, 0); width: 40.4069%; height: 46.5938px;">Port for MySQL connection, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%; height: 46.5938px;">The network port used to connect to MySQL. The default port is 3306.

</td></tr><tr style="height: 46.5938px;"><td style="border-color: rgb(0, 0, 0); width: 10.0102%; height: 46.5938px;">`DATABASE`

</td><td style="border-color: rgb(0, 0, 0); width: 40.4069%; height: 46.5938px;">Database Name for MySQL connection, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%; height: 46.5938px;">The name of the database being accessed. A MySQL instance can contain multiple databases.

</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details as shown in the image below, make sure to take a copy of these details and add it to the code moving ahead.

[![rivimage.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/mP2rivimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/mP2rivimage.png)

## **Prerequisites**

- **Install Node.js and NPM**
    - Check if Node.js is installed by running: `node -v`

- - If not installed, download it from [nodejs.org](https://nodejs.org) and install. Additionally, verify npm installation: `npm -v`

- **Install the mysql2 Package**
    - The <span class="s2">mysql2</span> package enables Node.js applications to interact with MySQL. Install it using: `npm install mysql2 --save`

## **Code**

Once all prerequisites are set up, create a new file named `<span class="s2">mysql.js</span>` and add the following code:

```javascript
const mysql = require("mysql2");

// Database connection configuration
const config = {
  host: "HOST",
  user: "USER",
  password: "PASSWORD",
  database: "DATABASE",
  port: PORT,
};

// Create a MySQL connection
const connection = mysql.createConnection(config);

// Connect to the database
connection.connect((err) => {
  if (err) {
    console.error("Connection failed:", err);
    return;
  }
  console.log("Connected to MySQL");

  // Run a test query to check the MySQL version
  connection.query("SELECT VERSION() AS version", (err, results) => {
    if (err) {
      console.error("Query execution failed:", err);
      connection.end();
      return;
    }

    console.log("MySQL Version:", results[0]);

    // Close the database connection
    connection.end((err) => {
      if (err) console.error("Error closing connection:", err);
    });
  });
});
```

To execute the script, open the terminal or command prompt and navigate to the directory where <span class="s1">mysql.js</span> is located. Once in the correct directory, run the script with the command:

```
node mysql.js
```

If the connection is successful, the terminal will display output similar to:

```
Connected to MySQL
MySQL Version: { version: '8.0.41' }
```

# Connecting with Python

This guide explains how to establish a connection between a Python application and a MySQL database using the `<span class="s3">mysql-connector-python</span>` package. It walks through the necessary setup, configuration, and execution of a simple SQL query.

## **Variables**

Certain parameters must be provided to establish a successful connection to a MySQL database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="border-collapse: collapse; border-color: rgb(0, 0, 0); width: 100%;"><thead><tr><th style="border-color: rgb(0, 0, 0); width: 10.4864%;">**Variable**

</th><th style="border-color: rgb(0, 0, 0); width: 39.9308%;">**Description**

</th><th style="border-color: rgb(0, 0, 0); width: 49.5828%;">**Purpose**

</th></tr></thead><tbody><tr><td style="border-color: rgb(0, 0, 0); width: 10.4864%;">`USER`

</td><td style="border-color: rgb(0, 0, 0); width: 39.9308%;">MySQL username, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%;">Identifies the database user who has permission to access the MySQL database.

</td></tr><tr><td style="border-color: rgb(0, 0, 0); width: 10.4864%;">`PASSWORD`

</td><td style="border-color: rgb(0, 0, 0); width: 39.9308%;">MySQL password, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%;">The authentication key is required for the specified USER to access the database.

</td></tr><tr><td style="border-color: rgb(0, 0, 0); width: 10.4864%;">`HOST`

</td><td style="border-color: rgb(0, 0, 0); width: 39.9308%;">Hostname for MySQL connection, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%;">The address of the server hosting the MySQL database.

</td></tr><tr><td style="border-color: rgb(0, 0, 0); width: 10.4864%;">`PORT`

</td><td style="border-color: rgb(0, 0, 0); width: 39.9308%;">Port for MySQL connection, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%;">The network port used to connect to MySQL. The default port is 3306.

</td></tr><tr><td style="border-color: rgb(0, 0, 0); width: 10.4864%;">`DATABASE`

</td><td style="border-color: rgb(0, 0, 0); width: 39.9308%;">Database Name for MySQL connection, from the Elestio service overview page

</td><td style="border-color: rgb(0, 0, 0); width: 49.5828%;">The name of the database being accessed. A MySQL instance can contain multiple databases.

</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details as shown in the image below, make sure to take a copy of these details and add it to the code moving ahead.

[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/88Kimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/88Kimage.png)

## **Prerequisites**

- **Install Python**
    - Check if Python is installed by running: `python --version`
    - If not installed, download it from [python.org](https://www.python.org/downloads/) and install it.

- **Install the `mysql-connector-python` Package**
    - The <span class="s2">mysql-connector-python</span> package enables Python applications to interact with MySQL. Install it using: `pip install mysql-connector-python`

## **Code**

Once all prerequisites are set up, create a new file named `<span class="s2">mysql_connect.py</span>` and add the following code:

```python
import mysql.connector

# Database connection configuration
config = {
    "host": "HOST",
    "user": "USER",
    "password": "PASSWORD",
    "database": "DATABASE",
    "port": PORT
}

try:
    # Establish the connection
    connection = mysql.connector.connect(**config)
    print("Connected to MySQL")

    # Create a cursor and execute a test query
    cursor = connection.cursor()
    cursor.execute("SELECT VERSION()")

    # Fetch and print the result
    version = cursor.fetchone()
    print("MySQL Version:", version[0])

except mysql.connector.Error as err:
    print("Connection failed:", err)

finally:
    if 'cursor' in locals():
        cursor.close()
    if 'connection' in locals() and connection.is_connected():
        connection.close()
        print("Connection closed")
```

To execute the script, open the terminal or command prompt and navigate to the directory where `<span class="s1">mysql_connect.py</span>` is located. Once in the correct directory, run the script with the command:

```
python mysql_connect.py
```

If the connection is successful, the terminal will display output similar to:

```
Connected to MySQL
MySQL Version: 8.0.41
Connection closed
```

# Connecting with PHP

This guide explains how to establish a connection between a PHP application and a MySQL database using the <span class="s3">mysqli</span> extension. It walks through the necessary setup, configuration, and execution of a simple SQL query.

## **Variables**

Certain parameters must be provided to establish a successful connection to a MySQL database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="width: 100%; border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead><tr><th style="width: 9.53403%; border-color: rgb(0, 0, 0);">**Variable**

</th><th style="width: 40.8831%; border-color: rgb(0, 0, 0);">**Description**

</th><th style="width: 49.5828%; border-color: rgb(0, 0, 0);">**Purpose**

</th></tr></thead><tbody><tr><td style="width: 9.53403%; border-color: rgb(0, 0, 0);">USER

</td><td style="width: 40.8831%; border-color: rgb(0, 0, 0);">MySQL username, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">Identifies the database user who has permission to access the MySQL database.

</td></tr><tr><td style="width: 9.53403%; border-color: rgb(0, 0, 0);">PASSWORD

</td><td style="width: 40.8831%; border-color: rgb(0, 0, 0);">MySQL password, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The authentication key is required for the specified USER to access the database.

</td></tr><tr><td style="width: 9.53403%; border-color: rgb(0, 0, 0);">HOST

</td><td style="width: 40.8831%; border-color: rgb(0, 0, 0);">Hostname for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The address of the server hosting the MySQL database.

</td></tr><tr><td style="width: 9.53403%; border-color: rgb(0, 0, 0);">PORT

</td><td style="width: 40.8831%; border-color: rgb(0, 0, 0);">Port for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The network port used to connect to MySQL. The default port is 3306.

</td></tr><tr><td style="width: 9.53403%; border-color: rgb(0, 0, 0);">DATABASE

</td><td style="width: 40.8831%; border-color: rgb(0, 0, 0);">Database Name for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The name of the database being accessed. A MySQL instance can contain multiple databases.

</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details as shown in the image below, make sure to take a copy of these details and add it to the code moving ahead.

[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/Ukwimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/Ukwimage.png)

## **Prerequisites**

- **Install PHP**
    - Check if PHP is installed by running: `php -v`
    - If not installed, download it from [php.net](https://www.php.net/downloads) and install.
    - Make sure the <span class="s1">mysqli</span> extension is enabled in your <span class="s1">php.ini</span> configuration.

### **Code**

Once all prerequisites are set up, create a new file named `<span class="s1">mysql_connect.php</span>` and add the following code:

```php
<?php
$host = "HOST";
$user = "USER";
$password = "PASSWORD";
$database = "DATABASE";
$port = PORT;

// Create connection
$conn = new mysqli($host, $user, $password, $database, $port);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected to MySQL<br>";

// Run a test query to check the MySQL version
$result = $conn->query("SELECT VERSION()");

if ($result) {
    $row = $result->fetch_assoc();
    echo "MySQL Version: " . $row["VERSION()"];
    $result->free();
} else {
    echo "Query execution failed: " . $conn->error;
}

// Close connection
$conn->close();
?>
```

To execute the script, run the PHP server in the directory where `<span class="s1">mysql_connect.php</span>` is located using:

```
php -S localhost:8000
```

Then, open a browser and go to:

```
http://localhost:8000/mysql_connect.php
```

If the connection is successful, the browser will display output similar to:

```
Connected to MySQL
MySQL Version: 8.0.36
```

# Connecting with Go

This guide explains how to establish a connection between a Go application and a MySQL database using the `<span class="s3">go-sql-driver/mysql</span>` package. It walks through the necessary setup, configuration, and execution of a simple SQL query.

## **Variables**

Certain parameters must be provided to establish a successful connection to a MySQL database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="width: 100%; border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead><tr><th style="width: 10.0102%; border-color: rgb(0, 0, 0);">**Variable**

</th><th style="width: 40.4069%; border-color: rgb(0, 0, 0);">**Description**

</th><th style="width: 49.5828%; border-color: rgb(0, 0, 0);">**Purpose**

</th></tr></thead><tbody><tr><td style="width: 10.0102%; border-color: rgb(0, 0, 0);">`USER`

</td><td style="width: 40.4069%; border-color: rgb(0, 0, 0);">MySQL username, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">Identifies the database user who has permission to access the MySQL database.

</td></tr><tr><td style="width: 10.0102%; border-color: rgb(0, 0, 0);">`PASSWORD`

</td><td style="width: 40.4069%; border-color: rgb(0, 0, 0);">MySQL password, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The authentication key is required for the specified USER to access the database.

</td></tr><tr><td style="width: 10.0102%; border-color: rgb(0, 0, 0);">`HOST`

</td><td style="width: 40.4069%; border-color: rgb(0, 0, 0);">Hostname for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The address of the server hosting the MySQL database.

</td></tr><tr><td style="width: 10.0102%; border-color: rgb(0, 0, 0);">`PORT`

</td><td style="width: 40.4069%; border-color: rgb(0, 0, 0);">Port for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The network port used to connect to MySQL. The default port is 3306.

</td></tr><tr><td style="width: 10.0102%; border-color: rgb(0, 0, 0);">`DATABASE`

</td><td style="width: 40.4069%; border-color: rgb(0, 0, 0);">Database Name for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The name of the database being accessed. A MySQL instance can contain multiple databases.

</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details, as shown in the image below. Make sure to take a copy of these details and add them to the code moving ahead.

[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/SQYimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/SQYimage.png)

## **Prerequisites**

- **Install Go**
    - Check if Go is installed by running: `go version`
    - If not installed, download it from [golang.org](https://golang.org/dl/) and install.

- **Install the MySQL Driver**
    - Use the following command to install the <span class="s2">go-sql-driver/mysql</span> driver: `go get -u github.com/go-sql-driver/mysql`

## **Code**

Once all prerequisites are set up, create a new file named `<span class="s2">mysql_connect.go</span>` and add the following code:

```go
package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	user := "USER"
	password := "PASSWORD"
	host := "HOST"
	port := "PORT"
	database := "DATABASE"

	// Construct DSN (Data Source Name)
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", user, password, host, port, database)

	// Open a connection
	db, err := sql.Open("mysql", dsn)
	if err != nil {
		log.Fatalf("Connection failed: %v", err)
	}
	defer db.Close()

	// Ping to verify connection
	if err := db.Ping(); err != nil {
		log.Fatalf("Ping failed: %v", err)
	}
	fmt.Println("Connected to MySQL")

	// Run a test query to check the MySQL version
	var version string
	err = db.QueryRow("SELECT VERSION()").Scan(&version)
	if err != nil {
		log.Fatalf("Query execution failed: %v", err)
	}
	fmt.Printf("MySQL Version: %s\n", version)
}
```

To execute the script, open the terminal and navigate to the directory where `<span class="s1">mysql_connect.go</span>` is located. Once in the correct directory, run the script with the commands:

```
go mod init example.com/mysqlconnect
go run mysql_connect.go
```

If the connection is successful, the terminal will display output similar to:

```
Connected to MySQL
MySQL Version: 8.0.36
```

# Connecting with Java

This guide explains how to establish a connection between a Java application and a MySQL database using the `<span class="s3">mysql-connector-j</span>` JDBC driver. It walks through the necessary setup, configuration, and execution of a simple SQL query.

## **Variables**

Certain parameters must be provided to establish a successful connection to a MySQL database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="width: 100%; border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead><tr><th style="width: 10.1293%; border-color: rgb(0, 0, 0);">**Variable**

</th><th style="width: 40.2879%; border-color: rgb(0, 0, 0);">**Description**

</th><th style="width: 49.5828%; border-color: rgb(0, 0, 0);">**Purpose**

</th></tr></thead><tbody><tr><td style="width: 10.1293%; border-color: rgb(0, 0, 0);">`USER`

</td><td style="width: 40.2879%; border-color: rgb(0, 0, 0);">MySQL username, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">Identifies the database user who has permission to access the MySQL database.

</td></tr><tr><td style="width: 10.1293%; border-color: rgb(0, 0, 0);">`PASSWORD`

</td><td style="width: 40.2879%; border-color: rgb(0, 0, 0);">MySQL password, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The authentication key is required for the specified USER to access the database.

</td></tr><tr><td style="width: 10.1293%; border-color: rgb(0, 0, 0);">`HOST`

</td><td style="width: 40.2879%; border-color: rgb(0, 0, 0);">Hostname for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The address of the server hosting the MySQL database.

</td></tr><tr><td style="width: 10.1293%; border-color: rgb(0, 0, 0);">`PORT`

</td><td style="width: 40.2879%; border-color: rgb(0, 0, 0);">Port for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The network port used to connect to MySQL. The default port is 3306.

</td></tr><tr><td style="width: 10.1293%; border-color: rgb(0, 0, 0);">`DATABASE`

</td><td style="width: 40.2879%; border-color: rgb(0, 0, 0);">Database Name for MySQL connection, from the Elestio service overview page

</td><td style="width: 49.5828%; border-color: rgb(0, 0, 0);">The name of the database being accessed. A MySQL instance can contain multiple databases.

</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details as shown in the image below, make sure to take a copy of these details and add it to the code moving ahead.

[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/Siiimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/Siiimage.png)

## **Prerequisites**

- **Install Java**
    - Check if Java is installed by running: `java -version`.
    - If not installed, download it from [oracle.com](https://www.oracle.com/java/technologies/javase-downloads.html) or install OpenJDK.

- **Install MySQL Connector/J**
    - Download the latest version `<span class="s2">mysql-connector-j</span>` from the [official MySQL site.](https://dev.mysql.com/downloads/connector/j/)

## **Code**

Once all prerequisites are set up, create a new file named `<span class="s2">MySQLConnect.java</span>` and add the following code:

```java
import java.sql.*;
import java.util.*;

public class MySQLConnect {
    public static void main(String[] args) {
        Map<String, String> config = new HashMap<>();
        for (int i = 0; i < args.length - 1; i += 2)
            config.put(args[i], args[i + 1]);

        String url = String.format("jdbc:mysql://%s:%s/%s?useSSL=true",
                config.get("-host"), config.get("-port"), config.get("-database"));

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            try (Connection conn = DriverManager.getConnection(url, config.get("-username"), config.get("-password"));
                 Statement stmt = conn.createStatement();
                 ResultSet rs = stmt.executeQuery("SELECT VERSION()")) {
                System.out.println("Connected to MySQL");
                if (rs.next()) System.out.println("MySQL Version: " + rs.getString(1));
            }
        } catch (Exception e) {
            System.err.println("Connection error: " + e.getMessage());
        }
    }
}
```

To compile and run the Java program, use the following commands in your terminal:

```
javac MySQLConnect.java && java -cp mysql-connector-j-9.3.0.jar:. MySQLConnect -host HOST -port PORT -database DATABASE -username avnadmin -password PASSWORD
```

If the connection is successful, the terminal will display output similar to:

```
Connected to MySQL
MySQL Version: 8.0.41
```

# Connecting with phpMyAdmin

phpMyAdmin is a widely used web-based interface for MySQL that allows you to manage databases, run SQL queries, and administer users through a graphical interface.

### **Variables**

To connect using phpMyAdmin, you’ll need the following connection parameters. When you deploy a MySQL service on Elestio, you also get a phpMyAdmin dashboard configured for you to use with these variables. These details are available in the Elestio service overview page:

<table border="1" id="bkmrk-variable-description" style="width: 58.4524%; height: 122.984px; border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead><tr style="height: 29.7969px;"><th style="width: 20.813%; height: 29.7969px; border-color: rgb(0, 0, 0);">**Variable**

</th><th style="width: 32.8605%; height: 29.7969px; border-color: rgb(0, 0, 0);">**Description**

</th><th style="width: 46.3265%; height: 29.7969px; border-color: rgb(0, 0, 0);">**Purpose**

</th></tr></thead><tbody><tr style="height: 46.5938px;"><td style="width: 20.813%; height: 46.5938px; border-color: rgb(0, 0, 0);">**USER**

</td><td style="width: 32.8605%; height: 46.5938px; border-color: rgb(0, 0, 0);">phpMyAdmin username

</td><td style="width: 46.3265%; height: 46.5938px; border-color: rgb(0, 0, 0);">Identifies the database user.

</td></tr><tr style="height: 46.5938px;"><td style="width: 20.813%; height: 46.5938px; border-color: rgb(0, 0, 0);">**PASSWORD**

</td><td style="width: 32.8605%; height: 46.5938px; border-color: rgb(0, 0, 0);">phpMyAdmin password

</td><td style="width: 46.3265%; height: 46.5938px; border-color: rgb(0, 0, 0);">Authentication key for the `USER`.

</td></tr></tbody></table>

You can find these values in your Elestio project dashboard under the Admin section.

[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/7dpimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/7dpimage.png)

### **Prerequisites**

Make sure the MySQL service is correctly deployed on Elestio and you are able to access the Admin section where phpMyAdmin is listed, similar to the example shown in the image above.

### **Setting Up the Connection**

Launch phpMyAdmin using the Admin UI URL and log in with the credentials acquired from the Elestio service dashboard. Once the login screen is loaded, enter the following:

- **Username**<span class="s1">: USER</span>
- <span class="s1">**Password**</span>: PASSWORD

Click on <span class="s2">**Go**</span> to access the phpMyAdmin interface.

[![Screenshot 2025-04-25 at 1.46.40 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-25-at-1-46-40-pm.jpg)](https://docs.elest.io/uploads/images/gallery/2025-04/screenshot-2025-04-25-at-1-46-40-pm.jpg)

Once logged in, you can see your available databases listed in the left panel. From here, you can:

- Run SQL queries through the **SQL** tab

[![Screenshot 2025-04-25 at 1.47.07 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-25-at-1-47-07-pm.jpg)](https://docs.elest.io/uploads/images/gallery/2025-04/screenshot-2025-04-25-at-1-47-07-pm.jpg)

- View or modify table structures

[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/9Rbimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/9Rbimage.png)

- Export or import database backups

[![Screenshot 2025-04-25 at 2.00.28 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-25-at-2-00-28-pm.jpg)](https://docs.elest.io/uploads/images/gallery/2025-04/screenshot-2025-04-25-at-2-00-28-pm.jpg)

- Manage users and privileges if applicable[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/76Fimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/76Fimage.png)

# Connecting with mysql

This guide explains how to connect to a MySQL database using the `<span class="s1">mysql</span>` 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:

<table border="1" id="bkmrk-variable-description" style="border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead><tr><th style="border-color: rgb(0, 0, 0);">**Variable**

</th><th style="border-color: rgb(0, 0, 0);">**Description**

</th><th style="border-color: rgb(0, 0, 0);">**Purpose**

</th></tr></thead><tbody><tr><td style="border-color: rgb(0, 0, 0);">`USER`

</td><td style="border-color: rgb(0, 0, 0);">MySQL username

</td><td style="border-color: rgb(0, 0, 0);">Identifies the database user.

</td></tr><tr><td style="border-color: rgb(0, 0, 0);">`PASSWORD`

</td><td style="border-color: rgb(0, 0, 0);">MySQL password

</td><td style="border-color: rgb(0, 0, 0);">Authenticates the user.

</td></tr><tr><td style="border-color: rgb(0, 0, 0);">`HOST`

</td><td style="border-color: rgb(0, 0, 0);">MySQL host address

</td><td style="border-color: rgb(0, 0, 0);">Endpoint to connect to the database service.

</td></tr><tr><td style="border-color: rgb(0, 0, 0);">`PORT`

</td><td style="border-color: rgb(0, 0, 0);">MySQL port number

</td><td style="border-color: rgb(0, 0, 0);">Default is usually <span class="s1">3306</span>, unless otherwise configured.

</td></tr><tr><td style="border-color: rgb(0, 0, 0);">`DATABASE`

</td><td style="border-color: rgb(0, 0, 0);">Database name

</td><td style="border-color: rgb(0, 0, 0);">The specific database you want to connect to.

</td></tr></tbody></table>

You can find all of these values in your Elestio project dashboard under the <span class="s1">**Admin**</span> or <span class="s1">**Database Info**</span> 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/](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
mysql -h HOST -P PORT -u USER -p DATABASE
```

- Replace `<span class="s1">HOST</span>`, `<span class="s1">PORT</span>`, `<span class="s1">USER</span>`, and `<span class="s1">DATABASE</span>` with the actual values.
- After running the command, you will be prompted to enter the `<span class="s1">PASSWORD</span>`.

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

```mysql
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:

```mysql
SELECT VERSION();
```

You should see output like this:

```mysql
+-----------+
| 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.