将自行管理的 MySQL 元存储区迁移到 Dataproc Metastore
本页面介绍如何通过创建 MySQL 转储文件并将元数据导入现有 Dataproc Metastore 服务,将外部自行管理的 MySQL 元存储区迁移到 Dataproc Metastore。
准备工作
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
启用 Dataproc Metastore API。
启用 API 所需的角色
如需启用 API,您需要拥有 Service Usage Admin IAM 角色 (
roles/serviceusage.serviceUsageAdmin),该角色包含serviceusage.services.enable权限。了解如何授予角色。
所需角色
如需获得创建 Dataproc metastore 和导入 MySQL metastore 所需的权限,请让您的管理员向您授予以下 IAM 角色:
-
如需创建服务和导入元数据:
- 项目的 Dataproc Metastore Editor (
roles/metastore.editor) - 项目的 Dataproc Metastore Admin (
roles/metastore.admin)
- 项目的 Dataproc Metastore Editor (
-
如需使用 Cloud Storage 对象(SQL 转储文件)进行导入:
- Storage Object Viewer (
roles/storage.objectViewer) Dataproc Metastore 服务代理的。例如,service-CUSTOMER_PROJECT_NUMBER@gcp-sa-metastore.。 - Storage Object Viewer (
roles/storage.objectViewer) 用户账号的。
- Storage Object Viewer (
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
这些预定义角色包含 创建 Dataproc Metastore 和导入 MySQL 元存储区所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
创建 Dataproc Metastore 和导入 MySQL 元存储区需要以下权限:
-
如需创建服务:
metastore.services.create项目的 -
如需导入元数据:
metastore.imports.create项目的 -
如需使用 Cloud Storage 对象(SQL 转储文件)进行导入:
-
storage.objects.getDataproc Metastore 服务代理的 。例如,service-CUSTOMER_PROJECT_NUMBER@gcp-sa-metastore. -
storage.objects.get用户账号的。
-
创建 Dataproc Metastore 服务
以下说明演示了如何创建 Dataproc Metastore 服务,您可以将 SQL 转储文件迁移到该服务。
控制台
在 Google Cloud 控制台中,打开 创建服务 页面:
Dataproc Metastore“创建服务”页面 在服务名称 字段中,输入
example-service。选择数据位置。如需了解如何选择区域,请参阅 Cloud 位置。
对于其他服务配置选项,请使用提供的默认值。
要创建并启动该服务,请点击提交按钮。
您的新服务会显示在“服务”列表中。
gcloud
运行以下 gcloud metastore services create 命令创建服务:
gcloud metastore services create example-service \
--location=LOCATION
将 LOCATION 替换为您计划在其中创建服务的 Compute Engine 区域。确保该地区提供 Dataproc Metastore。
REST
按照 API 说明使用 API Explorer 创建服务。
准备迁移
现在,您必须创建一个 MySQL 转储文件并将其放入 Cloud Storage 存储桶中,以准备存储在 Hive Metastore 数据库中的元数据以进行导入。
如需了解如何为迁移做好准备的步骤,请参阅导入前准备导入文件 。
导入元数据
现在您已准备好转储文件,请将其导入您的 Dataproc Metastore 服务。
如需了解如何将元数据导入 example-service 服务的步骤,请参阅 将文件导入 Dataproc Metastore
。
创建并关联 Managed Service for Apache Spark 集群
将元数据导入 Dataproc Metastore
example-service 服务后,请创建并关联 Managed Service for Apache Spark 集群
,该集群将该服务用作其 Hive Metastore。
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
- 在 Google Cloud 控制台中,前往 管理资源 页面。
- 如果您打算删除的项目已附加到某个组织,请展开名称列中的组织列表。
- 在项目列表中,选择要删除的项目,然后点击删除。
- 在对话框中输入项目 ID,然后点击 关停 以删除项目。
或者,您可以删除本教程中使用的资源:
删除 Dataproc Metastore 服务。
控制台
在 Google Cloud 控制台中,打开 Dataproc Metastore 页面:
在 Google Cloud 控制台中打开 Dataproc Metastore
通过选中相应的复选框,选择服务名称左侧的
example-service。在 Dataproc Metastore 页面顶部,点击删除以删除该服务。
在对话框中,点击删除以确认删除。
您的服务将不再出现在“服务”列表中。
gcloud
运行以下
gcloud metastore services delete命令删除服务:gcloud metastore services delete example-service \ --location=LOCATION将
LOCATION替换为您创建服务的 Compute Engine 区域。REST
按照 API 说明使用 API Explorer 删除服务。
所有删除操作都会立即成功执行。
删除 Cloud Storage 存储桶 以用于 Dataproc Metastore 服务。