Connecting to a Trino cluster
This section presents settings for connection to the Managed Service for Trino cluster using command line tools, from graphical IDEs and WebSQL. To learn how to connect from your application code, see Connection string examples.
You can connect to a Managed Service for Trino cluster with disabled private access only from the network the cluster resides in.
Note
If the connection requires a port, use port 443.
Command line tools
Trino CLI
If you do not have the Trino CLI yet, install it using the guide on the official Trino website
To connect to an Managed Service for Trino cluster:
-
Create an IAM token and put it to the
TRINO_PASSWORDenvironment variable:export TRINO_PASSWORD=$(yc iam create-token)This IAM token in
TRINO_PASSWORDwill be your password to the Managed Service for Trino cluster. To enable it, specify the--passwordflag upon connection. -
Connect to the Managed Service for Trino cluster:
./trino c-<cluster_ID>.trino.yandexcloud.net --user iam --passwordYou can get the cluster ID with the list of clusters in the folder.
Connecting from graphical IDEs
Before connecting:
-
Create an IAM token:
yc iam create-token -
Save the token. You will use it as a password for the connection.
- Create a data source:
- Select File → New → Data Source → Trino.
- Enter a name for the data source.
- Specify the connection settings on the General tab:
-
Host:
c-<cluster_ID>.trino.yandexcloud.net.If you are connecting to your Managed Service for Trino cluster via a service connection, specify
c-<cluster_ID>.trino.pe.yandexcloud.netas the host address. -
Port:
443. -
User:
iam. -
Password: Previously created IAM token.
-
- Click Test Connection. If the connection is successful, you will see the connection status and information about the DBMS and driver.
- Click OK to save the data source.
- Create a new DB connection:
- In the Database menu, select New connection.
- Select Trino from the list.
- Click Next.
- Specify the connection settings on the Main tab:
-
Host:
c-<cluster_ID>.trino.yandexcloud.net.If you are connecting to your Managed Service for Trino cluster via a service connection, specify
c-<cluster_ID>.trino.pe.yandexcloud.netas the host address. -
Port:
443. -
Under Authentication, specify:
- Username:
iam. - Password: Previously created IAM token.
- Username:
-
- Click Test Connection .... If the connection is successful, you will see the connection status, DBMS information, and driver details.
- Click Done to save the database connection settings.
WebSQL
-
Open the folder dashboard
. -
Go to Managed Service for Trino.
-
Open your Managed Service for Trino cluster.
-
Go to WebSQL.
-
Click Go to WebSQL.
-
In the SQL query editor that opens, run the following query:
SELECT version() AS version;The response will contain Trino version information.
Examples of connection strings
Python
Before connecting:
-
Install the dependencies:
pip3 install trino -
Create an IAM token and put it to the
TOKENenvironment variable:export TOKEN=$(yc iam create-token)
-
Code example:
connect.pyimport os from contextlib import closing from trino.dbapi import connect from trino.auth import BasicAuthentication TIMEOUT = 10 COORDINATOR_URL = 'c-<cluster_ID>.trino.yandexcloud.net' IAM_TOKEN = os.environ['TOKEN'] def get_version(): auth = BasicAuthentication(username='iam', password=IAM_TOKEN) with closing(connect(host=COORDINATOR_URL, port=443, auth=auth, request_timeout=TIMEOUT)) as conn: with closing(conn.cursor()) as cur: cur.execute('SELECT version() as version') rows = cur.fetchall() print(rows[0]) if __name__ == "__main__": get_version()You can request the cluster ID with the list of clusters in the folder.
If you are connecting to your Managed Service for Trino cluster via a service connection, specify
c-<cluster_ID>.trino.pe.yandexcloud.netas the host address. -
Connecting:
python3 connect.py
Java
Before connecting:
-
Install the dependencies:
sudo apt update && sudo apt install --yes openjdk-21-jre maven -
Create a directory for the Maven project:
cd ~/ && mkdir -p project/src/main/java/com/example && cd project/ -
Create a configuration file for Maven:
pom.xml
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>app</artifactId> <version>0.1.0</version> <packaging>jar</packaging> <properties> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>io.trino</groupId> <artifactId>trino-jdbc</artifactId> <version>469</version> </dependency> </dependencies> <build> <finalName>${project.artifactId}-${project.version}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.7.1</version> <executions> <execution> <goals> <goal>single</goal> </goals> <phase>package</phase> <configuration> <descriptorRefs> <descriptorRef> jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.example.App</mainClass> </manifest> </archive> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.4.2</version> <configuration> <archive> <manifest> <mainClass>com.example.App</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project> -
Create an IAM token and put it to the
TOKENenvironment variable:export TOKEN=$(yc iam create-token)
-
Code example:
src/main/java/com/example/App.javapackage com.example; import java.sql.DriverManager; import java.util.Properties; public class App { private static final String COORDINATOR_URL = "c-<cluster_ID>.trino.yandexcloud.net"; public static void main(String[] args) { String url = String.format("jdbc:trino://%s", COORDINATOR_URL); String iamToken = System.getenv("TOKEN"); Properties properties = new Properties(); properties.setProperty("user", "iam"); properties.setProperty("password", iamToken); properties.setProperty("SSL", "true"); try (var connection = DriverManager.getConnection(url, properties)) { var rs = connection.createStatement().executeQuery("SELECT version() as VERSION"); if (rs.next()) { System.out.println(rs.getString(1)); } } catch (Exception e) { e.printStackTrace(); } } }You can request the cluster ID with the list of clusters in the folder.
If you are connecting to your Managed Service for Trino cluster via a service connection, specify
c-<cluster_ID>.trino.pe.yandexcloud.netas the host address. -
Building and connecting:
mvn clean package && \ java -jar target/app-0.1.0-jar-with-dependencies.jar
Node.js
Before connecting:
-
Install the dependencies:
sudo apt update && sudo apt install --yes nodejs npm && \ npm install trino-client -
Create an IAM token and put it to the
TOKENenvironment variable:export TOKEN=$(yc iam create-token)
app.mjs
"use strict";
import {BasicAuth, Trino} from 'trino-client';
const COORDINATOR_URL = 'c-<cluster_ID>.trino.yandexcloud.net'
let TOKEN = process.env.TOKEN
async function get_version() {
const trino = Trino.create({server: COORDINATOR_URL,auth: new BasicAuth('iam', TOKEN)});
const query = await trino.query('SELECT version() as VERSION');
const queryResult = await query.next()
console.log(queryResult.value.data[0][0])
}
get_version();
You can request the cluster ID with the list of clusters in the folder.
If you are connecting to your Managed Service for Trino cluster via a service connection, specify c-<cluster_ID>.trino.pe.yandexcloud.net as the host address.
Connecting:
node app.mjs