trino常用命令

基本连接命令

# 基本连接
trino-cli --server http://localhost:8889

# 指定catalog和schema连接
trino-cli --server http://localhost:8889 --catalog hive --schema default

# 执行单个SQL语句并退出
trino-cli --server http://localhost:8889 --execute "show schemas from hive"

--execute参数比较有用,常用于执行一些ad hoc的查询:

image-20250719210757265

操作表的基础命令

# 查看所有可用的catalog
trino-cli --execute "SHOW CATALOGS"

# 查看特定catalog中的schema
trino-cli --execute "SHOW SCHEMAS FROM hive"

# 查看特定schema中的表
trino-cli --execute "SHOW TABLES FROM hive.default"

# 查看表结构
trino-cli --execute "DESCRIBE hive.default.users"


排查问题

# 查看正在运行的查询
trino-cli --execute "SELECT query_id, user, state, query FROM system.runtime.queries"

image-20250719210959452

# 查看查询详情
trino-cli --execute "SELECT * FROM system.runtime.queries WHERE query_id = '20250719_123632_00001_iwwd4'"

# 查看失败的查询
trino-cli --execute "SELECT query_id, user, state, query, error_code FROM system.runtime.queries WHERE state = 'FAILED'"

image-20250719211210993

# 查看集群节点状态
trino-cli --execute "SELECT * FROM system.runtime.nodes"

# 查看任务执行情况
trino-cli --execute "SELECT * FROM system.runtime.tasks"

image-20250719211327941

image-20250719211337515