Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Crea una instancia y escribe datos con la CLI de “cbt”
Si estás aprendiendo sobre Bigtable, puedes trabajar con una guía de inicio rápido para conocer los conceptos básicos que aplicarías a gran escala en un entorno de producción.
En esta guía de inicio rápido, harás lo siguiente:
Conéctate a una instancia de Bigtable.
Realizar tareas administrativas básicas
Escribir datos en una tabla
Leer datos de una tabla
Antes de comenzar
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.
En Nombre de la instancia, ingresa Quickstart instance.
En ID de instancia (Instance ID), ingresa quickstart-instance.
Haz clic en Continuar.
En Tipo de almacenamiento (Storage type), selecciona SSD.
Haz clic en Continuar.
En ID de clúster, ingresa quickstart-instance-c1.
En Región, selecciona una región cercana.
En Zona, selecciona Cualquiera.
En Modo de escalamiento de nodos, elige Asignación manual.
En Cantidad, selecciona 1.
Haz clic en Crear para crear la instancia.
Conéctate a la instancia
Configura la CLI de cbt para que use tu instancia y proyecto. Para ello, crea un archivo .cbtrc y reemplaza PROJECT_ID por el ID del proyecto en el que creaste la instancia de Bigtable:
Bigtable almacena datos en tablas, las cuales contienen filas. Cada fila se identifica con una clave de fila.
Los datos de una fila se organizan en familias de columnas, que son grupos de columnas.
Un calificador de columna identifica una columna individual dentro de una familia.
Puede haber varias celdas con marcas de tiempo en la intersección de una fila y una columna.
Crea una tabla con el nombre my-table.
cbt createtable my-table
Genera una lista de tus tablas:
cbt ls
El comando muestra un resultado similar a este:
my-table
Agrega una familia de columnas con el nombre cf1:
cbt createfamily my-table cf1
Genera una lista de tus familias de columnas:
cbt ls my-table
El comando muestra un resultado similar a este:
Family Name GC Policy
----------- ---------
cf1 <never>
Escribe los valores test-value1 y test-value2 en la fila r1, usando la familia de columnas cf1 y el calificador de columna c1:
cbt set my-table r1 cf1:c1=test-value1
cbt set my-table r1 cf1:c1=test-value2
Usa el comando cbt read para leer los datos que agregaste a la tabla:
cbt read my-table
La shell muestra un resultado similar al siguiente:
En la fila r1, se almacenan dos valores con marca de tiempo para la misma columna.
Limpia
Para evitar que se apliquen cargos a tu Google Cloud cuenta por los recursos que usaste en esta guía de inicio rápido, borra la instancia. Si borras el archivo .cbtrc, estarás listo para trabajar en otro proyecto.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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)."]]