Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Créer une instance et écrire des données avec la CLI cbt
Si vous découvrez Bigtable, ce guide de démarrage rapide peut vous aider à vous familiariser avec les principes de base que vous utiliseriez à grande échelle dans un environnement de production.
Dans ce guide de démarrage rapide, vous effectuez les actions suivantes :
Connexion à une instance Bigtable
Tâches d'administration de base
Écriture de données dans une table
Lecture des données d'une table
Avant de commencer
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
Dans le champ Nom de l'instance, saisissez Quickstart instance.
Dans le champ ID d'instance, saisissez quickstart-instance.
Cliquez sur Continuer.
Comme Type de stockage, sélectionnez SSD.
Cliquez sur Continuer.
Dans le champ ID de cluster, saisissez quickstart-instance-c1.
Dans le champ Région, sélectionnez une région à proximité de votre emplacement.
Dans le champ Zone, sélectionnez Toutes.
Dans le champ Mode de scaling des nœuds, sélectionnez Allocation manuelle.
Dans le champ Quantité, sélectionnez 1.
Cliquez sur Créer pour créer l'instance.
Se connecter à l'instance
Configurez la CLI cbt pour utiliser votre projet et votre instance en créant un fichier .cbtrc, en remplaçant PROJECT_ID par l'ID du projet dans lequel vous avez créé votre instance Bigtable :
Vous pouvez maintenant utiliser la CLI
cbt avec votre instance.
Lire et écrire des données
Bigtable enregistre les données dans des tables contenant des lignes. Chaque ligne est identifiée par une clé de ligne.
Les données d'une ligne sont organisées en familles de colonnes, qui sont des groupes de colonnes.
Un qualificatif de colonne identifie une seule colonne au sein d'une famille.
Il peut exister plusieurs cellules horodatées à l'intersection d'une ligne et d'une colonne.
Créez une table nommée my-table.
cbt createtable my-table
Répertoriez vos tables :
cbt ls
La commande affiche un résultat semblable à celui-ci :
my-table
Ajoutez une famille de colonnes nommée cf1 :
cbt createfamily my-table cf1
Répertoriez vos familles de colonnes :
cbt ls my-table
La commande affiche un résultat semblable à celui-ci :
Family Name GC Policy
----------- ---------
cf1 <never>
Écrivez les valeurs test-value1 et test-value2 dans la ligne r1 en utilisant la famille de colonnes cf1 et le qualificatif de colonne c1 :
cbt set my-table r1 cf1:c1=test-value1
cbt set my-table r1 cf1:c1=test-value2
Utilisez la commande cbt read pour lire les données que vous avez ajoutées à la table :
cbt read my-table
L'interface système affiche un résultat semblable à celui-ci :
Deux valeurs horodatées sont stockées pour la même colonne dans la ligne r1.
Effectuer un nettoyage
Pour éviter que les ressources utilisées dans ce guide de démarrage rapide ne soient facturées sur votre compte Google Cloud , supprimez l'instance. Dès lors que vous supprimez le fichier .cbtrc, vous êtes prêt à travailler sur un autre projet.
Supprimez la table my-table :
cbt deletetable my-table
Supprimez l'instance :
cbt deleteinstance quickstart-instance
Supprimez le fichier .cbtrc :
rm ~/.cbtrc
Facultatif : Révoquez les identifiants de gcloud CLI :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThis guide demonstrates how to use the \u003ccode\u003ecbt\u003c/code\u003e CLI to interact with a Bigtable instance, which is a fundamental skill for working with Bigtable at any scale.\u003c/p\u003e\n"],["\u003cp\u003eThe quickstart covers essential administrative actions, including creating a Bigtable instance, connecting to it using the \u003ccode\u003ecbt\u003c/code\u003e CLI, and configuring the connection via the \u003ccode\u003e.cbtrc\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eIt walks you through writing data to a table, where you define row keys, column families, and column qualifiers, and then it shows how to read that data back using the \u003ccode\u003ecbt read\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eThe guide also includes steps for cleanup, such as deleting the created table, the instance, and the configuration file (\u003ccode\u003e.cbtrc\u003c/code\u003e), along with an optional step to revoke credentials.\u003c/p\u003e\n"],["\u003cp\u003eYou can find more information about Bigtable, including codelabs, reference documentation, sample source code, and multiple 'hello world' examples on the provided links.\u003c/p\u003e\n"]]],[],null,["Create an instance and write data with the cbt CLI\n\nIf you're learning about Bigtable, you can work through a quickstart\nto get a taste of the fundamentals that you would use at scale in a production\nenvironment.\n\nIn this quickstart, you perform the following actions:\n\n- Connect to a Bigtable instance.\n- Perform basic administrative tasks.\n- Write data to a table.\n- Read data from a table.\n\nBefore you begin\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n- [Create or select a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects).\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n - Create a Google Cloud project:\n\n ```\n gcloud projects create PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with a name for the Google Cloud project you are creating.\n - Select the Google Cloud project that you created:\n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project name.\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Bigtable and Cloud Bigtable Admin APIs:\n\n\n ```bash\n gcloud services enable bigtable.googleapis.com bigtableadmin.googleapis.com\n ```\n-\n Grant roles to your user account. Run the following command once for each of the following\n IAM roles:\n `roles/bigtable.admin`\n\n ```bash\n gcloud projects add-iam-policy-binding PROJECT_ID --member=\"user:\u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e\" --role=ROLE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your project ID.\n - \u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e: the identifier for your user account---for example, `myemail@example.com`.\n - \u003cvar translate=\"no\"\u003eROLE\u003c/var\u003e: the IAM role that you grant to your user account.\n\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n- [Create or select a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects).\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n - Create a Google Cloud project:\n\n ```\n gcloud projects create PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with a name for the Google Cloud project you are creating.\n - Select the Google Cloud project that you created:\n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project name.\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Bigtable and Cloud Bigtable Admin APIs:\n\n\n ```bash\n gcloud services enable bigtable.googleapis.com bigtableadmin.googleapis.com\n ```\n-\n Grant roles to your user account. Run the following command once for each of the following\n IAM roles:\n `roles/bigtable.admin`\n\n ```bash\n gcloud projects add-iam-policy-binding PROJECT_ID --member=\"user:\u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e\" --role=ROLE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your project ID.\n - \u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e: the identifier for your user account---for example, `myemail@example.com`.\n - \u003cvar translate=\"no\"\u003eROLE\u003c/var\u003e: the IAM role that you grant to your user account.\n\n1. Run the following command to install the `cbt` CLI : \n\n gcloud components install cbt\n\n\u003cbr /\u003e\n\nCreate a Bigtable instance\n\n1. Open the **Create instance** page in the Google Cloud console.\n\n [Create an instance](https://console.cloud.google.com/bigtable/create-instance)\n2. For **Instance name** , enter `Quickstart instance`.\n\n3. For **Instance ID** , enter `quickstart-instance`.\n\n4. Click **Continue**.\n\n5. For **Storage type** , select **SSD**.\n\n6. Click **Continue**.\n\n7. For **Cluster ID** , enter `quickstart-instance-c1`.\n\n8. For **Region**, select a region near you.\n\n9. For **Zone** , select **Any**.\n\n10. For **Node scaling mode** , choose **Manual allocation**.\n\n11. For **Quantity** , select **1**.\n\n12. Click **Create** to create the instance.\n\nConnect to your instance\n\n1. Configure the\n `cbt` CLI\n to use your project and instance by creating a\n `.cbtrc` file, replacing \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with the ID\n for the project where you created your Bigtable instance:\n\n ```\n echo project = PROJECT_ID \u003e\u003e ~/.cbtrc && echo instance = quickstart-instance \u003e\u003e ~/.cbtrc\n ```\n2. Verify that you set up the `.cbtrc` file correctly:\n\n ```\n cat ~/.cbtrc\n ```\n\n The terminal displays the contents of the `.cbtrc` file, which looks similar\n to the following: \n\n ```\n project = PROJECT_ID\n instance = quickstart-instance\n ```\n\n Now you can use the\n `cbt` CLI\n with your instance.\n\nRead and write data\n\nBigtable stores data in *tables* , which contain *rows* . Each row\nis identified by a *row key*.\n\nData in a row is organized into *column families* , which are groups of columns.\nA *column qualifier* identifies a single column within a column family.\n\nThere can be multiple time-stamped cells at the intersection of\na row and column.\n\n1. Create a table named `my-table`.\n\n ```\n cbt createtable my-table\n ```\n2. List your tables:\n\n ```\n cbt ls\n ```\n\n The command displays output similar to the following:\n\n \u003cbr /\u003e\n\n ```\n my-table\n ```\n\n \u003cbr /\u003e\n\n3. Add one column family named `cf1`:\n\n ```\n cbt createfamily my-table cf1\n ```\n4. List your column families:\n\n ```\n cbt ls my-table\n ```\n\n The command displays output similar to the following:\n\n \u003cbr /\u003e\n\n ```\n Family Name GC Policy\n ----------- ---------\n cf1 \u003cnever\u003e\n ```\n\n \u003cbr /\u003e\n\n5. Write the values `test-value1` and `test-value2` to the row `r1`, using the\n column family `cf1` and the column qualifier `c1`:\n\n ```\n cbt set my-table r1 cf1:c1=test-value1\n cbt set my-table r1 cf1:c1=test-value2\n ```\n6. Use the `cbt read` command to read the data you added to the table:\n\n ```\n cbt read my-table\n ```\n\n The shell displays output similar to the following:\n\n \u003cbr /\u003e\n\n ```\n ----------------------------------------\n r1\n cf1:c1 @ 2023/03/22-06:56:11.323000\n \"test-value1\"\n cf1:c1 @ 2023/03/22-06:56:04.361000\n \"test-value2\"\n ```\n\n \u003cbr /\u003e\n\n Two timestamped values are stored for the same column in row `r1`.\n | **Note:** In this quickstart you set only two cells, but Bigtable lets you set up to 10,000 cells in a single write request.\n\nClean up\n\nTo avoid incurring charges to your Google Cloud account for the resources\nused in this quickstart, delete the instance. Deleting the `.cbtrc` file leaves\nyou ready to work on a different project.\n\n1. Delete the table `my-table`:\n\n ```\n cbt deletetable my-table\n ```\n2. Delete the instance:\n\n ```\n cbt deleteinstance quickstart-instance\n ```\n3. Delete the `.cbtrc` file:\n\n ```\n rm ~/.cbtrc\n ```\n\n \u003cbr /\u003e\n\n4. Optional: Revoke credentials from the gcloud CLI:\n\n ```\n gcloud auth revoke\n ```\n\nWhat's next\n\n- Work through a [Bigtable codelab](https://codelabs.developers.google.com/codelabs/cloud-bigtable-intro-java/index.html).\n- View the [`cbt` CLI\n reference documentation](/bigtable/docs/cbt-reference).\n- See sample source code for a [fraud detection use case](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/bigtable/use-cases/fraudDetection).\n- Write a Hello World application in [C#](/bigtable/docs/samples-c-sharp-hello), [C++](/bigtable/docs/samples-cpp-hello), [Go](/bigtable/docs/samples-go-hello), [Java](/bigtable/docs/samples-java-hello-world), [Node.js](/bigtable/docs/samples-nodejs-hello), [PHP](/bigtable/docs/samples-php-hello), [Python](/bigtable/docs/samples-python-hello), [Ruby](/bigtable/docs/samples-ruby-hello), or using the [HBase client for Java](/bigtable/docs/samples-hbase-java-hello)."]]