Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Criar uma instância e gravar dados com a CLI cbt
Se você estiver conhecendo o Bigtable, leia um guia de início rápido para saber sobre os conceitos básicos que usaria em reduzir escalonamento horizontal um ambiente de produção.
Neste guia de início rápido, você realiza as seguintes ações:
Conecte a uma instância do Bigtable.
realiza tarefas administrativas básicas;
grava dados em uma tabela;
lê dados de uma tabela.
Antes de começar
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.
Em Modo de escalonamento do nó, escolha Alocação manual.
Em Quantidade, selecione 1.
Clique em Criar para gerar a instância.
conectar-se à instância
Configure a
CLI cbt
para usar o projeto e a instância criando um
arquivo .cbtrc, substituindo PROJECT_ID pelo ID
do projeto em que
você criou a instância do Bigtable:
Agora, é possível usar a
CLI cbt
com sua instância.
ler e gravar dados
O Bigtable armazena dados em tabelas com linhas. Cada linha é identificada por uma chave de linha.
Os dados em uma linha são organizados em famílias de colunas, que são grupos de colunas.
Um qualificador de coluna identifica uma única coluna em um grupo de colunas.
Pode haver várias células com carimbo de data/hora na interseção de uma linha e uma coluna.
Crie uma tabela denominada my-table.
cbt createtable my-table
Liste as tabelas:
cbt ls
O comando exibe uma resposta semelhante a esta:
my-table
Adicione um grupo de colunas denominado cf1:
cbt createfamily my-table cf1
Liste os grupos de colunas:
cbt ls my-table
O comando exibe uma resposta semelhante a esta:
Family Name GC Policy
----------- ---------
cf1 <never>
Escreva os valores test-value1 e test-value2 na linha r1 usando o
grupo de colunas cf1 e o qualificador de coluna c1:
cbt set my-table r1 cf1:c1=test-value1
cbt set my-table r1 cf1:c1=test-value2
Use o comando cbt read para ler os dados que você adicionou à tabela:
Dois valores com carimbo de data/hora são armazenados para a mesma coluna na linha r1.
Limpar
Para evitar cobranças na sua conta do Google Cloud pelos recursos
usados neste guia de início rápido, exclua a instância. Com a exclusão do arquivo .cbtrc, você está pronto para trabalhar em outro projeto.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-27 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,["# Quickstart: Create an instance and write data with the cbt CLI\n\nCreate an instance and write data with the cbt CLI\n==================================================\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\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--------------------------\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------------------------\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-------------------\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--------\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\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)."]]