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