Create a dedicated gcloud configuration that allows disable authentication
and override the endpoint. Once configured, your gcloud commands will be
sent to the emulator instead of the production service. No worries, you'll
be able to switch back to your previous configurations at the end of this
guide.
$ gcloud config configurations create emulator
$ gcloud config set auth/disable_credentials true
$ gcloud config set project [your-project-id] $ gcloud config set api_endpoint_overrides/spanner http://localhost:9020/
Create a test database to host your pipeline output.
make sure the local Spanner emulator runs in a separated tab.
Point your client libraries to the emulator. When pipeline starts, the
client library automatically checks for SPANNER_EMULATOR_HOST and connects
to the emulator if it is running.
$ export SPANNER_EMULATOR_HOST=localhost:9010
Run the data migration pipeline in dry run mode. Verify metrics like total
record count.
$ go run main.go -input-csv-path "test-data.csv" -spanner-database "projects/[your-project-id]/instances/test-instance/databases/testdb" -spanner-table "mytable" -dry-run=true
flag -dry-run=true is to active the dry run mode.
Run the data migration pipeline in the real run and write into Spanner.
$ go run main.go -input-csv-path "test-data.csv" -spanner-database "projects/[your-project-id]/instances/test-instance/databases/testdb" -spanner-table "mytable"
Verify the MySQL CSV dump has been successfully migrated to your Spanner
database