All Products
Search
Document Center

E-MapReduce:Connect to Trino by using the CLI

Last Updated:Aug 20, 2026

After you create a cluster with the Trino service, you can use the command-line interface (CLI) to connect to Trino for quick and simple data queries.

Prerequisites

A cluster has been created with the Trino service selected. For more information about how to create a cluster, see Create a cluster.

Limitations

Ranger and Kerberos cannot be enabled in the same cluster simultaneously.

Datalake and custom clusters

Note

Enabling Kerberos Authentication when you create a cluster creates a high-security cluster. Otherwise, a common cluster is created.

Common clusters

  1. Log on to the cluster using SSH. For more information, see Log on to a cluster.

  2. Run the following command to connect to the Trino CLI.

    Note

    For E-MapReduce (EMR) 3.44.0 or later and EMR 5.10.0 or later, the console displays the service as Trino. For versions earlier than EMR 3.44.0 and EMR 5.10.0, the console displays the service as Presto.

    EMR 3.44.0 or later and EMR 5.10.0 or later

    trino --server master-1-1:9090

    Versions earlier than EMR 3.44.0 and EMR 5.10.0

    presto --server master-1-1:9090
  3. Run the following command to view table data.

    select * from <catalog>.<schema>.<table>;

    The parameters in the command are as follows:

    • <catalog>: The name of the data source.

    • <schema>: The name of the database.

    • <table>: The table to query.

      For example, to view the data in the test table in the default database of a Hive data source, run the select * from hive.default.test; command.

  4. Optional: Run the quit; command to exit the Trino CLI.

High-security clusters

  1. Log on to the cluster using SSH. For more information, see Log on to a cluster.

  2. Run the following command to connect to the Trino CLI.

    EMR 3.44.0 or later and EMR 5.10.0 or later

    trino --server https://${FQDN}:7778 \
           --krb5-config-path /etc/krb5.conf \
           --keystore-path /etc/emr/trino-conf/keystore \
           --keystore-password ${pwd} \
           --krb5-keytab-path /etc/emr/trino-conf/trino.keytab \
           --krb5-principal trino/${FQDN}@${REALM} \
           --krb5-remote-service-name trino \
           --user trino/${FQDN}
           --catalog ${CATALOG}

    Versions earlier than EMR 3.44.0 and EMR 5.10.0

    Note

    For EMR 3.44.0 or later and EMR 5.10.0 or later, the console displays the service as Trino. For versions earlier than EMR 3.44.0 and EMR 5.10.0, the console displays the service as Presto.

    presto --server https://${FQDN}:7778 \
           --krb5-config-path /etc/krb5.conf \
           --keystore-path /etc/emr/trino-conf/keystore \
           --keystore-password ${pwd} \
           --krb5-keytab-path /etc/emr/trino-conf/trino.keytab \
           --krb5-principal trino/${FQDN}@${REALM} \
           --krb5-remote-service-name trino \
           --user trino/${FQDN}

    Parameter

    Description

    ${FQDN}

    The fully qualified domain name (FQDN) of the master-1-1 node. You can get the FQDN by running the hostname -f command. The format is master-1-1.c-xxxxxxx.cn-xxxxxx.emr.aliyuncs.com.

    --krb5-config-path

    The value of http.authentication.krb5.config in the config.properties file. The value is /etc/krb5.conf.

    --keystore-path

    The value of http-server.https.keystore.path in the config.properties file. The value is /etc/emr/trino-conf/keystore.

    --keystore-password

    The value of http-server.https.keystore.key in the config.properties file. This parameter corresponds to ${pwd}. To obtain the value, run the awk -F= '/http-server.https.keystore.key/{print $2}' ${TRINO_CONF_DIR}/config.properties command on the master-1-1 node.

    --krb5-keytab-path

    The value of http-server.authentication.krb5.keytab in the config.properties file. The value is /etc/emr/trino-conf/trino.keytab.

    ${REALM}

    The Kerberos realm, which you can find in the http-server.authentication.krb5.user-mapping.pattern property of the config.properties file. In EMR, the realm format is EMR.C-XXXXXX.COM.

    --krb5-remote-service-name

    The value of http-server.authentication.krb5.service-name in the config.properties file. The value is trino.

    ${CATALOG}

    The name of the data source to connect to. For example, specify --catalog hive to connect to a Hive data source.

  3. Run the following command to view the schemas in the current catalog.

    show schemas;
  4. Optional: Run the quit; command to exit the Trino CLI.

Legacy datalake clusters (Hadoop)

Note

On Hadoop clusters, the EMR console displays the service as Presto.

Common clusters

  1. Log on to the cluster using SSH. For more information, see Log on to a cluster.

  2. Run the following command to connect to the Presto CLI.

    presto --server emr-header-1:9090 --catalog hive --schema default --user hadoop

    The parameters in the command are as follows:

    • --server emr-header-1:9090: The address and port of the Presto server.

    • --catalog hive: The name of the data source to connect to. In this example, the data source is Hive. To connect to a different data source, change this value.

    • --schema default: The name of the database or schema to use. In this example, the default database is used. You can change this parameter based on your requirements.

    • --user hadoop: The username for authentication.

  3. Run the following command to view the schemas in the current catalog.

    show schemas;
  4. Optional: Run the quit; command to exit the Presto CLI.

High-security clusters

  1. Log on to the cluster using SSH. For more information, see Log on to a cluster.

  2. Add a principal and export its keytab file.

    1. Run the following command to start the Kerberos administration tool.

      • EMR 3.30.0 or later and EMR 4.5.1 or later:

        sh /usr/lib/has-current/bin/admin-local.sh /etc/ecm/has-conf -k /etc/ecm/has-conf/admin.keytab
      • Versions earlier than EMR 3.30.0 and EMR 4.5.1:

        sh /usr/lib/has-current/bin/hadmin-local.sh /etc/ecm/has-conf -k /etc/ecm/has-conf/admin.keytab
    2. Run the following command to add a principal with a random key.

      addprinc -randkey test
      Note

      This example adds a principal named test.

    3. Run the following command to export the keytab file.

      xst -k /home/test.keytab test

      By default, the keytab file is exported to the /home/ directory.

  3. Run the following command to enter the Presto CLI.

    presto --server https://<hostname>:7778 \
           --catalog hive \
           --schema default \
           --keystore-path /etc/ecm/presto-conf/keystore \
           --keystore-password <passwd> \
           --krb5-keytab-path <keytab_file> \
           --krb5-principal <username>@EMR.<cluster_id>.COM \
           --krb5-remote-service-name presto \
           --user <username>

    Parameter

    Description

    <hostname>

    The hostname. To obtain the hostname, run the hostname command on the emr-header-1 node. The format is emr-header-1.cluster-xxx.

    <passwd>

    The password. To obtain the password, run the sed -n 's/http-server.https.keystore.key=\([^;]*\)/\1/p' /etc/ecm/presto-conf/config.properties command on the emr-header-1 node.

    <keytab_file>

    The path to the exported keytab file. In this example, the path is /home/test.keytab.

    <username>

    The principal for the keytab file. In this example, the principal is test.

    <cluster_id>

    The cluster ID. To obtain the cluster ID, run the hostname | grep -Eo '[0-9]+$' command on the emr-header-1 node.

  4. Run the following command to view the schemas in the current catalog.

    show schemas;
  5. Optional: Run the quit; command to exit the Presto CLI.

Related documentation

For complex data queries, analysis, and processing, or to integrate query results into a Java application, connect to Trino using JDBC. For more information, see Connect to Trino by using JDBC.