Commands
Database Management
wrangler d1 create
wrangler d1 create
Create a new D1 database.Options:Example:Note: If jurisdictions are set, the location hint is ignored.
The name of the new D1 database
A hint for the primary location of the new DB. Options:
weur: Western Europeeeur: Eastern Europeapac: Asia Pacificoc: Oceaniawnam: Western North Americaenam: Eastern North America
The location to restrict the D1 database to run and store data within to comply with local regulations. Options:
eu: The European Unionfedramp: FedRAMP-compliant data centers
Automatically update your wrangler configuration file with the new database binding
The name of the binding to use in your wrangler configuration file
wrangler d1 list
wrangler d1 list
List all D1 databases in your account.Options:Example:
Return output as clean JSON
wrangler d1 info
wrangler d1 info
wrangler d1 delete
wrangler d1 delete
SQL Execution
wrangler d1 execute
wrangler d1 execute
Execute a SQL command or SQL file against a D1 database.Options:Example:You must provide either
The name or binding of the DB
The SQL query you wish to execute, or multiple queries separated by
;A .sql file to ingest
Answer “yes” to any prompts (alias:
-y)Execute commands/files against a local DB for use with wrangler dev
Execute commands/files against a remote D1 database
Execute commands/files against a preview D1 database
Specify directory to use for local persistence (for use with
--local)Return output as clean JSON
--command or --file. By default, executes against local database unless --remote is specified.Data Import/Export
wrangler d1 export
wrangler d1 export
Export the contents or schema of your database as a .sql file.Options:Example:You cannot specify both
The name of the D1 database to export
Path to the SQL file for your export
Export from your local DB you use with wrangler dev
Export from a remote D1 database
Specify which tables to include in export (can be specified multiple times)
Only output table contents, not the DB schema
Only output table schema, not the contents of the DBs themselves
--no-schema and --no-data.Migrations
wrangler d1 migrations create
wrangler d1 migrations create
wrangler d1 migrations list
wrangler d1 migrations list
View a list of unapplied migration files.Options:Example:
The name or binding of the DB
Check migrations against a local DB for use with wrangler dev
Check migrations against a remote DB
Check migrations against a preview D1 DB
Specify directory to use for local persistence (you must use
--local with this flag)wrangler d1 migrations apply
wrangler d1 migrations apply
Apply any unapplied D1 migrations.Options:Example:This command will prompt you to confirm the migrations you are about to apply. If applying a migration results in an error, it will be rolled back, and the previous successful migration will remain applied.
The name or binding of the DB
Execute commands/files against a local DB for use with wrangler dev
Execute commands/files against a remote DB
Execute commands/files against a preview D1 DB
Specify directory to use for local persistence (you must use
--local with this flag)Time Travel
wrangler d1 time-travel info
wrangler d1 time-travel info
Retrieve information about a database at a specific point-in-time using Time Travel.Options:Example:For more information about Time Travel, see the D1 Time Travel documentation.
The name or binding of the DB
Accepts a Unix (seconds from epoch) or RFC3339 timestamp (e.g. 2023-07-13T08:46:42.228Z) to retrieve a bookmark for
Return output as clean JSON
wrangler d1 time-travel restore
wrangler d1 time-travel restore
Restore a database back to a specific point-in-time.Options:Example:You must provide either
The name or binding of the DB
Bookmark to use for time travel
Accepts a Unix (seconds from epoch) or RFC3339 timestamp (e.g. 2023-07-13T08:46:42.228Z) to retrieve a bookmark for (within the last 30 days)
Return output as clean JSON
--timestamp or --bookmark, but not both. This will overwrite all data in the database and cancel in-flight queries and transactions.For more information about Time Travel, see the D1 Time Travel documentation.