coding-memo/memo/spanner-setting.md
2025-08-23 01:07:13 +09:00

1.0 KiB

Install gcloud cli

https://cloud.google.com/sdk/docs/install

Run spanner docker

https://cloud.google.com/spanner/docs/emulator#start-emulator-gcloud

Set gcloud cli to point to local

export SPANNER_EMULATOR_HOST=localhost:9010

Run spanner code on terminal

# Create instances
gcloud spanner instances create testinstance \
  --config=emulator-config \
  --description="Test Instance" \
  --nodes=1

# Create database
gcloud spanner databases create testdb --instance=testinstance

# Create table
gcloud spanner databases ddl update testdb --instance=testinstance \
  --ddl="CREATE TABLE Singers (
    SingerId INT64 NOT NULL,
    FirstName STRING(1024),
    LastName  STRING(1024),
    SingerInfo BYTES(MAX)
  ) PRIMARY KEY (SingerId)"

Connect to spanner through dbeaver

  1. Install DBeaver CE (free) on Mac.
  2. Install the Spanner JDBC driver.
  3. Create a new connection → Google Cloud Spanner. • Project ID: test-project • Instance: testinstance • Database: testdb • set autoConfigEmulator to true