All Products
Search
Document Center

AnalyticDB:IMPORT FOREIGN SCHEMA

Last Updated:Mar 28, 2026

Use IMPORT FOREIGN SCHEMA to batch create MaxCompute foreign tables in an AnalyticDB for MySQL cluster.

Prerequisites

Before you begin, ensure that you have:

  • An AnalyticDB for MySQL cluster running V3.2.2.0 or later

    To view and update the minor version, log on to the AnalyticDB for MySQL console and go to the Configuration Information section of the Cluster Information page.
  • Elastic Network Interface (ENI) enabled on the cluster

    Important

    To enable ENI, log on to the AnalyticDB for MySQL console, go to the cluster details page, and choose Cluster Management > Cluster Information in the left-side navigation pane. In the Network Information section, turn on ENI. Enabling or disabling ENI interrupts database connections for approximately 2 minutes. No read or write operations can be performed during this period.

  • A MaxCompute project in the same region as your AnalyticDB for MySQL cluster

  • The CIDR blocks of the virtual private cloud (VPC) where your cluster resides added to the IP address whitelist of the MaxCompute project

    To find the CIDR blocks, view the VPC ID on the Cluster Information page of the AnalyticDB for MySQL console, then look up the VPC in the VPC console. For how to configure the whitelist in MaxCompute, see Manage IP address whitelists.
  • A foreign server created for the cluster — see Create a foreign server in this topic

Quick start

The following end-to-end example shows the complete workflow: create a foreign server, then import foreign tables.

Step 1: Create a foreign server.

CREATE SERVER maxcompute_server
TYPE = 'ODPS'
SERVER_PROPERTIES = '{
    "endpoint":"http://service.cn-hangzhou-vpc.maxcompute.aliyun-inc.com/api",
    "accessid":"STS.****************",
    "accesskey":"yourAccessKeySecret"
}';

Step 2: Import all tables from a MaxCompute project.

IMPORT FOREIGN SCHEMA my_project
FROM maxcompute_server
INTO my_adb_schema;

This creates a foreign table in AnalyticDB for MySQL for every table in my_project.

Syntax

IMPORT FOREIGN SCHEMA odps_project
[LIMIT TO (table_name[, ...])]
FROM server_name
INTO adb_schema
[OPTIONS (
  if_table_exist 'error|ignore|update',
  if_type_unsupport 'error|ignore',
  table_prefix 'table_prefix',
  table_suffix 'table_suffix')]

Parameters

ParameterRequiredDescription
odps_projectYesThe name of the MaxCompute project.
table_name[,...]NoThe MaxCompute tables to import. If omitted, all tables in the project are imported.
server_nameYesThe name of the foreign server.
adb_schemaYesThe name of the database in the AnalyticDB for MySQL cluster.
if_table_existNoHow to handle name conflicts with existing tables. Default: error. See options below.
if_type_unsupportNoHow to handle unsupported data types. Default: error. See options below.
table_prefixNoA prefix to add to each foreign table name. By default, foreign tables use the same name as the corresponding MaxCompute table.
table_suffixNoA suffix to add to each foreign table name. By default, foreign tables use the same name as the corresponding MaxCompute table.

if_table_exist options

ValueBehaviorUse when
error (default)Reports an error and lists the conflicting tables. No tables are created.You want strict control and must review conflicts before proceeding.
ignoreSkips tables with conflicting names; creates all other tables.Running idempotent scripts — the import can be re-run safely without overwriting existing tables.
updateOverwrites tables with conflicting names; creates all other tables.Syncing schema changes from MaxCompute — existing foreign tables are refreshed to match the latest MaxCompute schema.

if_type_unsupport options

ValueBehavior
error (default)Reports an error and lists the unsupported data types and the tables that contain them.
ignoreSkips tables that contain unsupported data types; creates all other tables.

Examples

Import all tables from a project

Import all tables from my_project into the my_adb_schema database:

IMPORT FOREIGN SCHEMA my_project
FROM maxcompute_server
INTO my_adb_schema;

Import selected tables with naming options

Import only the customer and order tables, adding a pre_ prefix and _suf suffix to the foreign table names. Overwrite any existing tables with the same name, and skip tables with unsupported data types:

IMPORT FOREIGN SCHEMA my_project
LIMIT TO (customer, order)
FROM maxcompute_server
INTO my_adb_schema
OPTIONS (
    if_table_exist 'update',
    if_type_unsupport 'ignore',
    table_prefix 'pre_',
    table_suffix '_suf'
);

This creates foreign tables named pre_customer_suf and pre_order_suf in AnalyticDB for MySQL.

Manage foreign servers

A foreign server stores the connection configuration for a MaxCompute project. Create one before running IMPORT FOREIGN SCHEMA.

Create a foreign server

Syntax

CREATE SERVER <server_name>
TYPE = 'ODPS'
SERVER_PROPERTIES = '{
    "endpoint":"<endpoint>",
    "accessid":"<accesskey_id>",
    "accesskey":"<accesskey_secret>"
}'

Parameters

ParameterRequiredDescription
server_nameYesThe name of the foreign server. Up to 64 characters; can contain letters, digits, and underscores (_); must start with a letter or underscore.
TYPE='ODPS'YesThe foreign server type. Set to ODPS.
endpointYesThe VPC endpoint of MaxCompute. Only VPC endpoints are supported. For endpoint values, see Endpoints.
accessidYesThe AccessKey ID of an Alibaba Cloud account or a Resource Access Management (RAM) user with access to MaxCompute. For how to get an AccessKey ID and AccessKey secret, see Accounts and permissions.
accesskeyYesThe AccessKey secret of the Alibaba Cloud account or RAM user that has the permissions to access MaxCompute. For how to get an AccessKey ID and AccessKey secret, see Accounts and permissions.

Example

CREATE SERVER maxcompute_server
TYPE = 'ODPS'
SERVER_PROPERTIES = '{
    "endpoint":"http://service.cn-hangzhou-vpc.maxcompute.aliyun-inc.com/api",
    "accessid":"STS.****************",
    "accesskey":"yourAccessKeySecret"
}';

Query foreign servers

List all foreign servers:

SHOW SERVER

Query a specific foreign server by name:

SHOW SERVER WHERE SERVER_NAME='<server_name>';

Example:

SHOW SERVER WHERE SERVER_NAME='maxcompute_server';

Query foreign servers by type:

SHOW SERVER WHERE SERVER_TYPE='<server_type>';

For MaxCompute servers, set server_type to ODPS:

SHOW SERVER WHERE SERVER_TYPE='ODPS';

Rename a foreign server

Syntax

ALTER SERVER <server_name> RENAME <new_server_name>

Parameters

ParameterRequiredDescription
server_nameYesThe current name of the foreign server.
new_server_nameYesThe new name of the foreign server.

Example

ALTER SERVER maxcompute_server RENAME mc_server;

Delete a foreign server

Deleting a foreign server disconnects the connection between AnalyticDB for MySQL and MaxCompute established through that server.

Syntax

DROP SERVER <server_name>

Parameters

ParameterRequiredDescription
server_nameYesThe name of the foreign server to delete.

Example

DROP SERVER maxcompute_server;