Google Cloud 提供「身分與存取權管理」(IAM) 功能,可讓您以更精細的方式授予使用者特定 Google Cloud 資源的存取權,避免其他資源遭到未經授權者擅自存取。您可以使用 Google Cloud 控制台、API 的 IAM 方法或 Google Cloud CLI 取得及設定資料庫遷移服務的權限。詳情請參閱「
授予、變更及撤銷資源的存取權」。
提供檔案中的 JSON 資料
使用 cURL 搭配 API 時,您必須使用命令列提供屬性值。如果您要使用密碼或安全性金鑰等機密值,在指令列上提供這些值會造成安全性風險。為提高安全性,您可以建立包含 API 呼叫 JSON 資料的檔案,並在指令列提供檔案路徑。
如要透過檔案向 cURL API 呼叫提供 JSON 資料,請按照下列步驟操作:
建立檔案,並在 --data 欄位中加入所有以單引號括住的內容。
請加入彎號,但不要加入單引號。
在指令列中,提供檔案路徑 (前面加上 @ 字元) 做為 --data 參數:
--data@<path-to-file>/<filename>
使用長時間執行的 API 呼叫
某些 API 呼叫 (例如物件建立) 可能需要一段時間才能完成。由於 API 為非同步,因此即使作業仍在進行中,呼叫也會立即傳回。如果後續的 API 呼叫使用新建立的物件,則必須等待第一個作業完成,才能繼續進行。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-18 (世界標準時間)。"],[[["\u003cp\u003eThe Database Migration Service provides a REST API for managing connection profiles and migration jobs programmatically, with detailed resources and methods available in the API Reference.\u003c/p\u003e\n"],["\u003cp\u003eUsers can interact with the API directly using tools like cURL, requiring proper request formatting, user authentication, and response handling, or indirectly via the Google Cloud CLI and Google Cloud Console, which simplify these processes.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize the API, it must be enabled in the Google Cloud project, either through the Google Cloud console or via the gcloud CLI, and the user must possess appropriate permissions, such as Database Migration Admin, Viewer, or Cloud SQL Admin.\u003c/p\u003e\n"],["\u003cp\u003eFor security, sensitive data for API calls can be stored in a file and referenced in cURL commands, instead of being directly entered in the command line.\u003c/p\u003e\n"],["\u003cp\u003eThe API handles long-running operations asynchronously, allowing users to manage operations via the API, such as showing details, listing, or deleting them.\u003c/p\u003e\n"]]],[],null,["# Use the Database Migration Service API\n\nDatabase Migration Service provides a REST API for administering your connection profiles and migration jobs programmatically. The REST API is defined by resources associated with creating and managing connection profiles and migration jobs. For details about all resources\nand their methods, see the\n[Database Migration Service API Reference](/database-migration/docs/reference/rest).\n\nWhen you send requests directly to the Database Migration Service REST API, you must create the\ncorrect form of the request, authorize the request as an authenticated user, and\nprocess any responses returned. Many of the tasks in this documentation provide\nAPI examples using [cURL](http://curl.haxx.se).\n\nFor more examples of using the APIs, see the page for the request in the\n[Database Migration Service API Reference](/database-migration/docs/reference/rest). Each page has\nexamples calling the API in several programming languages, as well as a\nrequest-specific Explorer to help you see what goes into a well-formed request\nand what to expect in the response.\n\nYou're also using the Database Migration Service API, indirectly, when you use any of the\nfollowing ways of administering instances:\n\n- [Google Cloud CLI](/sdk): A command-line interface (CLI) that you can use to work with your instances.\n\n- [Google Cloud console](https://console.cloud.google.com/): A graphical web interface.\n\nThe advantage of using these methods, especially the\nGoogle Cloud console, is that they can greatly simplify administering your\nconnection profiles and migration jobs (depending on your use case). If you're just starting out with\nDatabase Migration Service, then we recommend that you start with one of these tools first\nbefore working with the REST API directly.\n\nEnable the API\n--------------\n\nTo use the Database Migration Service API, you need to enable it: \n\n### Console\n\n1. [Enable the Database Migration Service API](https://console.cloud.google.com/apis/library/datamigration.googleapis.com).\n2. Select your project.\n3. Select **Continue**.\n\n### gcloud\n\n1. Enter the following to display the project IDs for your Google Cloud projects: \n\n ```bash\n gcloud projects list\n ```\n2. Set your default project: \n\n ```bash\n gcloud config set project YOUR_PROJECT_ID\n ```\n3. Enable the Cloud SQL Admin API: \n\n ```bash\n gcloud services enable datamigration.googleapis.com\n ```\n\nPermissions\n-----------\n\nYou must have the required permissions to use the Database Migration Service API. These permissions include:\n\n- Database Migration Admin: With this permission, a user gains access to all resources of Database Migration Service used to manage connection profiles and migration jobs.\n- Database Migration Viewer: With this permission, a user has read-only access to connection profiles and migration jobs in Database Migration Service.\n- Cloud SQL Admin: With this permission, a user can create and manage connection profiles and migration jobs for Cloud SQL in Database Migration Service.\n\nGoogle Cloud offers Identity and Access Management (IAM), which lets you give more granular access to specific Google Cloud resources and prevents unwanted access to other resources. You can get and set permissions for Database Migration Service using the Google Cloud console, the IAM methods of the API, or the Google Cloud CLI. For more information, see\n[Granting, changing, and revoking access to resources](/iam/docs/granting-changing-revoking-access).\n\nProvide JSON data from a file\n-----------------------------\n\nWhen you use the API with cURL, you provide property values using the command\nline. If you're working with sensitive values such as passwords or security\nkeys, providing them on the command line poses a security risk. For increased\nsecurity, you can create a file containing the JSON data for the API call, and\nprovide the path to the file on the command line.\n\nTo provide JSON data to your cURL API call from a file:\n\n1. Create a file containing everything enclosed in single quotes for the\n `--data` field.\n\n Include the curly brackets, but don't include the single quotes.\n2. At the command line, provide the path to the file, preceded by the\n `@` character, as the `--data` parameter:\n\n ```bash\n --data @\u003cpath-to-file\u003e/\u003cfilename\u003e\n ```\n\n \u003cbr /\u003e\n\nWork with long-running API calls\n--------------------------------\n\nSome API calls, such as object creation, can take some time to complete. Because\nthe API is asynchronous, the call returns immediately, even if the operation is\nstill in progress. If a subsequent API call uses the newly created object, then you\nmust wait for the first operation to complete before proceeding.\n\nYou can use the Database Migration Service API to\n[manage operations](/sdk/gcloud/reference/database-migration/operations). This includes:\n\n- [Showing details about an operation](/sdk/gcloud/reference/database-migration/operations/describe)\n- [Listing operations for a region](/sdk/gcloud/reference/database-migration/operations/list)\n- [Deleting an operation](/sdk/gcloud/reference/database-migration/operations/delete)\n\nDatabase Migration Service and Google APIs Discovery Service\n------------------------------------------------------------\n\n[Google APIs Discovery Service](/discovery) is a service that you can use to discover Google APIs. For example, when you use the [Google APIs Explorer](/apis-explorer) tool, you're using the Discovery Service.\n\n\u003cbr /\u003e\n\nIn the Discovery Service, Database Migration Service is represented as \"datamigration\" (for example:\nhttps://**datamigration**.googleapis.com/$discovery/rest?version=v1)."]]