Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite finden Sie ein Beispiel für die Verwendung von Apache Hive mit einem Dataproc Metastore-Dienst. In diesem Beispiel starten Sie eine Hive-Sitzung in einem Dataproc-Cluster und führen dann Beispielbefehle aus, um eine Datenbank und eine Tabelle zu erstellen.
Wenn Sie Hive verwenden möchten, stellen Sie mit SSH eine Verbindung zum Dataproc-Cluster her, der mit Ihrem Dataproc Metastore-Dienst verknüpft ist.
Sobald die Verbindung hergestellt ist, können Sie Hive-Befehle über das SSH-Terminalfenster in Ihrem Browser ausführen, um Ihre Metadaten zu verwalten.
Mit Hive verbinden
Rufen Sie in der Google Cloud Console die Seite VM-Instanzen auf.
Klicken Sie in der Liste der VM-Instanzen in der Zeile der Dataproc-VM-Instanz, zu der Sie eine Verbindung herstellen möchten, auf SSH.
Im Stammverzeichnis des Knotens wird ein Browserfenster mit einer Ausgabe ähnlich der folgenden geöffnet:
Führen Sie die folgenden Befehle in der SSH-Sitzung aus, um Hive zu starten und eine Datenbank und Tabelle zu erstellen:
Starten Sie Hive.
hive
Erstellen Sie eine Datenbank mit dem Namen myDatabase.
create database myDatabase;
Zeige die Datenbank an, die du erstellt hast.
show databases;
Verwenden Sie die Datenbank, die Sie erstellt haben.
use myDatabase;
Erstellen Sie eine Tabelle mit dem Namen myTable.
create table myTable(id int,name string);
Listen Sie die Tabellen unter myDatabase auf.
show tables;
Die Tabellenzeilen in der von Ihnen erstellten Tabelle anzeigen
desc MyTable;
Wenn Sie die folgenden Befehle ausführen, wird eine Ausgabe generiert, die etwa so aussieht:
$hive
hive> show databases;
OK
default
hive> create database myDatabase;
OK
hive> use myDatabase;
OK
hive> create table myTable(id int,name string);
OK
hive> show tables;
OK
myTable
hive> desc myTable;
OK
id int
name string
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-02 (UTC)."],[[["\u003cp\u003eThis guide demonstrates how to use Apache Hive with a Dataproc Metastore service by launching a Hive session on a Dataproc cluster.\u003c/p\u003e\n"],["\u003cp\u003eYou must first create a Dataproc Metastore service and attach it to a Dataproc cluster, including setting the Hive metastore password.\u003c/p\u003e\n"],["\u003cp\u003eConnect to Hive through an SSH connection to the associated Dataproc cluster VM instance.\u003c/p\u003e\n"],["\u003cp\u003eOnce connected, you can run Hive commands to create and manage databases and tables, as demonstrated with the \u003ccode\u003emyDatabase\u003c/code\u003e and \u003ccode\u003emyTable\u003c/code\u003e examples.\u003c/p\u003e\n"],["\u003cp\u003eThe guide also presents examples of how to perform commands such as showing databases and tables, creating databases and tables, and showing descriptions of the tables.\u003c/p\u003e\n"]]],[],null,["# Use Apache Hive with Dataproc Metastore\n\nThis page shows you an example of using Apache Hive with a Dataproc Metastore\nservice. In this example, you launch a Hive session on a Dataproc cluster,\nand then run sample commands to create a database and table.\n\nBefore you begin\n----------------\n\n- Create a [Dataproc Metastore service](/dataproc-metastore/docs/create-service).\n- Attach the [Dataproc Metastore service to a Dataproc cluster](/dataproc-metastore/docs/attach-dataproc).\n - [Set the Hive metastore password](/dataproc/docs/concepts/configuring-clusters/secure-hive-metastore#set_the_hive_metastore_password).\n\nConnect to Apache Hive\n----------------------\n\nTo start using Hive, use SSH to connect to the Dataproc\ncluster that's associated with your Dataproc Metastore service.\nOnce connected, you can run Hive commands from the SSH terminal window\nin your browser to manage your metadata.\n\n**To connect to Hive**\n\n1. In the Google Cloud console, go to the [VM\n Instances](https://console.cloud.google.com/compute/instances) page.\n2. In the list of virtual machine instances, click **SSH** in the row of the Dataproc VM instance that you want to connect to.\n\nA browser window opens in your home directory on the node with an output similar\nto the following: \n\n Connected, host fingerprint: ssh-rsa ...\n Linux cluster-1-m 3.16.0-0.bpo.4-amd64 ...\n ...\n example-cluster@cluster-1-m:~$\n\nTo start Hive and create a database and table, run the following commands\nin the SSH session:\n\n1. Start Hive.\n\n hive\n\n2. Create a database named `myDatabase`.\n\n create database myDatabase;\n\n3. Show the database that you created.\n\n show databases;\n\n4. Use the database that you created.\n\n use myDatabase;\n\n5. Create a table named `myTable`.\n\n create table myTable(id int,name string);\n\n6. List the tables under `myDatabase`.\n\n show tables;\n\n7. Show the table rows in the table that you created.\n\n desc MyTable;\n\nRunning the following commands generates output similar to the following: \n\n $hive\n\n hive\u003e show databases;\n OK\n default\n hive\u003e create database myDatabase;\n OK\n hive\u003e use myDatabase;\n OK\n hive\u003e create table myTable(id int,name string);\n OK\n hive\u003e show tables;\n OK\n myTable\n hive\u003e desc myTable;\n OK\n id int \n name string \n\nWhat's next\n-----------\n\n- [Import metadata](/dataproc-metastore/docs/import-metadata)\n- [Export metadata](/dataproc-metastore/docs/export-metadata)\n- [Use Spark SQL](/dataproc-metastore/docs/use-spark)"]]