Skip to main content

Connect to Aiven for MySQL® from the command line

Here, you can find how to connect to your MySQL via the command line with a choice of tools:

Using mysqlsh

Variables

These are the placeholders you will need to replace in the code sample:

VariableDescription
SERVICE_URIURL for the MySQL connection, from Aiven Console > the Overview page of your service

Prerequisites

For this example you need the mysqlsh client installed. You can install this by following the MySQL shell installation documentation.

Code

Execute the following from a terminal window to connect to the MySQL database:

mysqlsh --sql SERVICE_URI

You can execute this query to test:

MySQL ssl defaultdb SQL> select 1 + 2 as three;
+-------+
| three |
+-------+
| 3 |
+-------+
1 row in set (0.0539 sec)

Using mysql

Variables

These are the placeholders you need to replace in the code sample:

VariableDescription
USER_HOSTHostname for MySQL connection
USER_PORTPort for MySQL connection
USER_PASSWORDPassword of your Aiven for MySQL connection
DB_NAMEDatabase Name of your Aiven for MySQL connection

Prerequisites

For this example you need the mysql client installed. You can install it by following the MySQL client installation documentation.

Code

This step requires to manually specify individual parameters. You can find those parameters in Aiven Console > the Overview page of your service.

Once you have these parameters, execute the following from a terminal window to connect to the MySQL database:

mysql --user avnadmin --password=USER_PASSWORD --host USER_HOST --port USER_PORT DB_NAME
warning

If you are providing the password via the command line, you must pass it as shown; putting a space between the parameter name and value will cause the password to be parsed incorrectly.