

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 Athena 中建立資料庫
<a name="creating-databases"></a>

Athena 中的資料庫是您在其中建立的資料表的邏輯群組。建立資料庫之前，請先建立查詢輸出位置。

**Topics**
+ [建立查詢輸出位置](creating-databases-prerequisites.md)
+ [建立 資料庫](creating-databases-query-editor.md)

# 建立查詢輸出位置
<a name="creating-databases-prerequisites"></a>

如果您尚未在 Amazon S3 中設定查詢輸出位置，請執行下列先決條件步驟。

**若要建立查詢輸出位置**

1. 使用您用於 Athena 的相同 AWS 區域 和 帳戶，依照步驟 （例如，使用 Amazon S3 主控台） 在 [Amazon S3 中建立儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket.html)體，以保留您的 Athena 查詢結果。您可將此儲存貯體設定為您的查詢輸出位置。

1. 前往 [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home) 開啟 Athena 主控台。

1. 如果這是您第一次造訪 Athena 主控台 AWS 區域，請選擇**探索查詢編輯器**以開啟查詢編輯器。此外，Athena 會於查詢編輯器中開啟。

1. 選擇 **Edit Settings** (編輯設定) 以在 Amazon S3 中設定查詢結果位置。  
![\[選擇編輯設定。\]](http://docs.aws.amazon.com/zh_tw/athena/latest/ug/images/getting-started-choose-view-settings.png)

1. 對於 **Manage settings** (管理設定)，請執行下列其中一項動作：
   + 在 **Location of query result** (查詢結果的位置) 方塊中，輸入您在 Amazon S3 中為查詢結果建立的儲存貯體路徑。在路徑中加上 `s3://` 作為字首。
   + 選擇 **Browse S3** (瀏覽 S3)，選擇您在目前區域建立的 Amazon S3 儲存貯體，然後選擇 **Choose** (選擇)。  
![\[在 Amazon S3 中指定要從 Athena 接收查詢結果的位置。\]](http://docs.aws.amazon.com/zh_tw/athena/latest/ug/images/getting-started-setting-results-location.png)

1. 選擇**儲存**。

1. 選擇 **Editor** (編輯器) 以切換至查詢編輯器。  
![\[選擇 Editor (編輯器)。\]](http://docs.aws.amazon.com/zh_tw/athena/latest/ug/images/getting-started-choose-editor.png)

# 建立 資料庫
<a name="creating-databases-query-editor"></a>

在您設定查詢結果位置之後，在 Athena 主控台查詢編輯器中建立資料庫輕鬆簡單。

**若要使用 Athena 查詢編輯器建立資料庫**

1. 前往 [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home) 開啟 Athena 主控台。

1. 在**編輯器**索引標籤上，輸入 Hive 資料定義語言 (DDL) 命令 `CREATE DATABASE myDataBase`。以您想要的資料庫名稱取代 *myDatabase*。有關資料庫名稱的限制，請參閱 [為資料庫、資料表和資料欄命名](tables-databases-columns-names.md)。

1. 選擇 **Run** (執行) 或按 **Ctrl\$1ENTER**。

1. 如需使您的資料庫訂為目前的資料庫，請從查詢編輯器左側的 **Database** (資料庫) 選單中選取它。

如需 Athena 資料庫控制許可的相關資訊，請參閱[在 中設定資料庫和資料表的存取權 AWS Glue Data Catalog](fine-grained-access-to-glue-resources.md)。