推特 阿里云技术文档正文

将MaxCompute数据导入AnalyticDB for MySQL_通过INSERT外表方式导入导出MaxCompute数据_大数据_数据接入_分析型数据库MySQL版

admin 阿里云技术文档 2020-02-11 177 0
阿里云服务器优惠

将MaxCompute数据导入AnalyticDB for MySQL

前提条件

  • 根据MaxCompute准备工作快速入门在MaxCompute中准备数据源。

    例如通过CREATE TABLE,在MaxCompute中创建以下数据表。如果您已经有数据源,请跳过该步骤。

    1. CREATE TABLE IF NOT EXISTS odps_nopart_import_test
    2. (
    3. uid STRING,
    4. other STRING
    5. )
    6. LIFECYCLE 3;

    在DataWorks中,通过导入数据方式将文件odps_nopart_import_test.txt中的数据导入odps_nopart_import_test表。

  • 根据AnalyticDB for MySQL快速入门,完成创建实例、设置白名单、创建账号和数据库等准备工作。

实施步骤

  1. 连接AnalyticDB for MySQL,进入目标数据库。

    本示例将odps_nopart_import_test表中的数据导入AnalyticDB for MySQL的test_adb数据库中。

  2. 通过CREATE TABLE,在test_adb数据库中创建外部映射表odps_nopart_import_test_external_table

    1. CREATE TABLE IF NOT EXISTS odps_nopart_import_test_external_table
    2. (
    3. uid string,
    4. other string
    5. )
    6. ENGINE='ODPS'
    7. TABLE_PROPERTIES='{
    8. "endpoint":"http://service.cn.maxcompute.aliyun-inc.com/api",
    9. "accessid":"L*******FsE",
    10. "accesskey":"CcwF********iWjv",
    11. "project_name":"odps_project1",
    12. "table_name":"odps_nopart_import_test"
    13. }'
    参数 说明
    ENGINE=’ODPS’ 表示该表是外部表,使用的存储引擎是MaxCompute。
    TABLE_PROPERTIES 用于告知AnalyticDB for MySQL如何访问MaxCompute中的数据。
    endpoint MaxCompute的EndPoint(域名节点)

    注意:目前仅支持AnalyticDB for MySQL通过MaxCompute的VPC网络Endpoint访问MaxCompute。

    如何查看MaxCompute Endpoint,请参见配置Endpoint

    accessid 您访问MaxCompute源表时所持有的Access Key Secret

    如何获取您的accessidaccesskey,请参见获取账号的AK信息

    accesskey 您访问MaxCompute源表时所持有的AccessKey ID
    project_name MaxCompute中的工作空间名称。
    table_name MaxCompute中的数据源表名。
  3. 通过CREATE TABLE,在adb_demo数据库中创建目标表adb_nopart_import_test存储从MaxCompute中导入的数据。

    1. CREATE TABLE IF NOT EXISTS adb_nopart_import_test
    2. (
    3. uid string,
    4. other string
    5. )
    6. DISTRIBUTE BY HASH(uid);
  4. 执行INSERT语句将MaxCompute数据导入AnalyticDB for MySQL。

    1. insert into adb_nopart_import_test
    2. select * from odps_nopart_import_test_external_table
    1. select * from adb_nopart_import_test
    2. +---------------+-----------------+
    3. | uid | other |
    4. +---------------+-----------------+
    5. | 4 | other4 |
    6. | 6 | other6 |
    7. | 5 | other5 |
    8. | 2 | other2 |
    9. | 1 | other1 |
    10. | 3 | other3 |
    11. | 7 | other7 |
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论

-----