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 |
---|---|---|
|
MySQL username |
Identifies the database user. |
|
MySQL password |
Authenticates the user. |
|
MySQL host address |
Endpoint to connect to the database service. |
|
MySQL port number |
Default is usually 3306, unless otherwise configured. |
|
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
, andDATABASE
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.
No Comments