The MySQL connector lets Trino query and write data in an external MySQL database. Use it to run federated queries that join MySQL tables with other data sources in your cluster, such as Hive or Iceberg tables, or to join data across two MySQL instances.
Prerequisites
Before you begin, ensure that you have:
A Hadoop or DataLake cluster with the Trino service deployed, or a Trino cluster. See Create a cluster.
An ApsaraDB RDS for MySQL instance. See Create an ApsaraDB RDS for MySQL instance.
Limitations
Only Hadoop or Trino clusters on E-MapReduce (EMR) V3.38.0 and later support the MySQL connector.
Supported MySQL versions: 5.7, 8.0, or later (ApsaraDB RDS for MySQL only).
The coordinator node and all worker nodes must be able to reach MySQL. The default port is 3306.
The following SQL statements are not supported:
DELETE,GRANT,REVOKE,SHOW GRANTS,SHOW ROLES,SHOW ROLE GRANTS.
Configure the MySQL connector
For general connector configuration steps, see Configure a connector.
Minimum required configuration
Each MySQL catalog is defined by a .properties file. The minimum configuration requires three properties:
connection-url=jdbc:mysql://rm-2ze5ipacsu8265q****.mysql.rds.aliyuncs.com:3306
connection-user=<your-username>
connection-password=<your-password>To find your connection-url, see View and manage instance endpoints and ports.
In the EMR console, these properties map to configuration items on the mysql.properties tab of the Trino service's Configure tab.
| Configuration item | Description |
|---|---|
connection-url | The JDBC URL of your ApsaraDB RDS for MySQL instance. |
connection-user | The username for database access. The account must have read (and write, if needed) permissions on the target tables. |
connection-password | The password for the account specified by connection-user. |
Connect to multiple MySQL instances
To connect Trino to more than one MySQL instance, create a separate .properties file for each instance in the etc/catalog directory. Each file name becomes the catalog name in Trino — for example, sales.properties creates a catalog named sales.
File names must be unique and end with .properties.
To add a second MySQL catalog using the EMR console:
On the Configure tab of the Trino service, click the mysql.properties tab. Set
connection-url,connection-user, andconnection-passwordfor your first MySQL instance. To add properties not listed by default, click Add Configuration Item at the top of the tab. For details, see the Add configuration items section of "Manage configuration items".Click the connector[x].properties tab (where
xis an integer starting from 1) to configure additional MySQL catalogs. Repeat for each additional instance.Save the configuration:
At the bottom of the Configure tab, click Save.
In the dialog box, enter a reason in Execution Reason and click Save.
Restart the Trino service:
In the upper-right corner, choose More > Restart.
Enter a reason in Execution Reason and click OK.
In the Confirm dialog, click OK.
Data type mappings
DECIMAL type with precision greater than 38
MySQL's DECIMAL type supports precision up to 65, but Trino's DECIMAL type supports a maximum precision of 38. To map a MySQL DECIMAL(p, s) where p > 38, set the decimal_mapping configuration property (or the corresponding session property) to allow_overflow. The mapped Trino type uses a fixed precision of 38; the scale is controlled by decimal-default-scale and the rounding behavior by decimal-rounding-mode.
By default, any value that requires rounding or truncation during mapping causes a runtime failure. Set decimal-rounding-mode to one of the following values to change this behavior:
| Value | Behavior |
|---|---|
UNNECESSARY | Fail if rounding is required (default) |
UP | Round away from zero |
DOWN | Round toward zero |
CEILING | Round toward positive infinity |
FLOOR | Round toward negative infinity |
HALF_UP | Round toward nearest neighbor; ties round up |
HALF_DOWN | Round toward nearest neighbor; ties round down |
HALF_EVEN | Round toward nearest neighbor; ties round to even |
General configuration properties
Use the following properties to control how unsupported data types are handled and how metadata is cached.
| Property | Description | Default |
|---|---|---|
unsupported-type-handling | How to handle columns with unsupported data types. IGNORE makes those columns inaccessible; CONVERT_TO_VARCHAR converts them to unbounded VARCHAR. | IGNORE |
jdbc-types-mapped-to-varchar | Forces conversion of comma-separated JDBC types to unbounded VARCHAR. | — |
case-insensitive-name-matching | When set to true, database and table names are matched case-insensitively. | false |
case-insensitive-name-matching.cache-ttl | How long to cache case-insensitive name mappings. | 1 minute |
metadata.cache-ttl | How long to cache table and column statistics. Set to 0 to disable caching. | 0 (disabled) |
metadata.cache-missing | When set to true, the absence of metadata (e.g., a missing table) is also cached. | false |
Query MySQL data
The MySQL connector maps each MySQL database to a Trino schema. All queries use the three-level naming format catalog.schema.table, where catalog is the name of your .properties file (for example, mysql).
Step 1: Log on to the cluster over SSH. See Log on to a cluster.
Step 2: Connect to the Trino CLI.
For a DataLake cluster:
trino --server master-1-1:9090 --catalog iceberg --schema defaultFor a Hadoop or Trino cluster:
trino --server emr-header-1:9090 --catalog iceberg --schema defaultStep 3: List all MySQL databases available in the catalog.
SHOW SCHEMAS FROM mysql;Step 4: List tables in a specific database. In this example, web is the name of an ApsaraDB RDS for MySQL database.
SHOW TABLES FROM mysql.web;Step 5: Inspect the columns in a table.
DESCRIBE mysql.web.clicks;Alternatively:
SHOW COLUMNS FROM mysql.web.clicks;Step 6: Query the table.
SELECT * FROM mysql.web.clicks;Pushdown
The MySQL connector supports pushdown for the following operators and functions. Pushdown moves computation to the MySQL side, reducing the data transferred to Trino.
Pushdown is applied where it improves performance. When pushing down an operation risks incorrect results, the connector prioritizes correctness and executes the operation in Trino instead.
Operators:
Join
Limit
Top-N
Functions:
avg()count()max()min()sum()stddev()stddev_pop()stddev_samp()variance()var_pop()var_samp()
For more details on how pushdown works in Trino, see Pushdown in the Trino documentation.