将MaxCompute数据导入AnalyticDB for MySQL_通过INSERT外表方式导入导出MaxCompute数据_大数据_数据接入_分析型数据库MySQL版
将MaxCompute数据导入AnalyticDB for MySQL
前提条件
根据MaxCompute准备工作和快速入门在MaxCompute中准备数据源。
例如通过CREATE TABLE,在MaxCompute中创建以下数据表。如果您已经有数据源,请跳过该步骤。
CREATE TABLE IF NOT EXISTS odps_nopart_import_test
(
uid STRING,
other STRING
)
LIFECYCLE 3;
在DataWorks中,通过导入数据方式将文件odps_nopart_import_test.txt中的数据导入odps_nopart_import_test表。
根据AnalyticDB for MySQL快速入门,完成创建实例、设置白名单、创建账号和数据库等准备工作。
实施步骤
连接AnalyticDB for MySQL,进入目标数据库。
本示例将
odps_nopart_import_test
表中的数据导入AnalyticDB for MySQL的test_adb
数据库中。通过CREATE TABLE,在
test_adb
数据库中创建外部映射表odps_nopart_import_test_external_table
。CREATE TABLE IF NOT EXISTS odps_nopart_import_test_external_table
(
uid string,
other string
)
ENGINE='ODPS'
TABLE_PROPERTIES='{
"endpoint":"http://service.cn.maxcompute.aliyun-inc.com/api",
"accessid":"L*******FsE",
"accesskey":"CcwF********iWjv",
"project_name":"odps_project1",
"table_name":"odps_nopart_import_test"
}'
参数 说明 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。 如何获取您的
accessid
和accesskey
,请参见获取账号的AK信息。accesskey 您访问MaxCompute源表时所持有的AccessKey ID。 project_name MaxCompute中的工作空间名称。 table_name MaxCompute中的数据源表名。 通过CREATE TABLE,在
adb_demo
数据库中创建目标表adb_nopart_import_test
存储从MaxCompute中导入的数据。CREATE TABLE IF NOT EXISTS adb_nopart_import_test
(
uid string,
other string
)
DISTRIBUTE BY HASH(uid);
执行INSERT语句将MaxCompute数据导入AnalyticDB for MySQL。
insert into adb_nopart_import_test
select * from odps_nopart_import_test_external_table
select * from adb_nopart_import_test
+---------------+-----------------+
| uid | other |
+---------------+-----------------+
| 4 | other4 |
| 6 | other6 |
| 5 | other5 |
| 2 | other2 |
| 1 | other1 |
| 3 | other3 |
| 7 | other7 |
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
评论