Skip to content

Instantly share code, notes, and snippets.

@arafathusayn
Created April 3, 2024 17:54
Show Gist options
  • Save arafathusayn/206da35c11b823ab5f25485069cc96f9 to your computer and use it in GitHub Desktop.
Save arafathusayn/206da35c11b823ab5f25485069cc96f9 to your computer and use it in GitHub Desktop.
How I migrated my database from PlanetScale

My step by step workflow

$ pscale auth login
# this opened my browser where I was logged in on PlanetScale
  • I checked with my database name and production branch
$ pscale shell database1 main

# my database name: database1
# my production branch: main
database1/main: show tables;
# and some other sql queries
  • I took a backup in the ./dump directory
$ pscale database dump database1 main --output dump
Starting to dump all tables from database database1 to folder dump
Dumping is finished! (elapsed time: 4.458032834s)

It looked like this in dump directory:

$ find dump
dump
dump/database1.table-name-1.00001.sql
dump/database1.table-name-1-schema.sql
dump/database1.table-name.00001.sql
dump/database1.table-name-2-schema.sql
dump/database1.table-name-2-schema.sql
dump/database1.table-name-2.00001.sql
dump/metadata
  • I merged all schema files into one file:
$ cat dump/database1*schema*.sql > dump/schema.sql

# notice database1 is my own database name, you might have a different one so edit accordingly
  • I merged other files that don't have schema in their names into one seed file:
$ ls dump/*.sql | grep -v 'schema' | xargs cat > dump/seed_without_schema.sql
  • Finally I imported the SQL files in my other hosted MySQL databases.

Thanks for reading!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment