Overview
PlanetScale provides an import tool in the dashboard that allows you to painlessly import an existing internet-accessible MySQL or MariaDB database into a PlanetScale database with no downtime.NoteYou must be an Organization Administrator to use this feature.
Connect to your external database
To import an existing database into PlanetScale:1
Head to your PlanetScale dashboard and click on “New database” > “Import database,” which will bring you to the Import Setup page.
2
Give your imported database a name and select a region from the dropdown.
3
We recommend using the same name as the database you’re importing from to avoid updating any database name references throughout your application code. If you’d prefer to use a different database name, make sure to update your app where applicable once you fully switch over to PlanetScale.
4
Fill in the following connection values with information from your existing hosted database:
- Host name — The address where the database is hosted.
- Port — The port where your database is hosted. The default MySQL port is
3306
. - Database name — The exact database name you want to import.
- SSL verification mode — If your database server provides a valid SSL certificate, please set this to
Required,
otherwise selectDisabled
. - Username — The user’s username used to connect to the database. This user must have
read
andwrite
access.
NoteYou must have binary logs enabled on the
database you’re importing.
5
You’ll have the option to Authenticate with password or Authenticate with mTLS. To authenticate with a password, type in the password for the username you entered. Make sure the user has
read
and write
access to this database.For the “Authenticate with mTLS option,” you’ll need to provide the following:- SSL client certificate — Certificate to authenticate PlanetScale with your database server.
- SSL client key — This is the private key for the client certificate
6
From here, you can proceed to testing the connection or click “Show advanced settings” for more options.
7
(Optional) Under Advanced settings, you have the option to enter the following:
- SSL server name override
- SSL CA certificate chain — If your database server provides a certificate with a non-trusted root CA, please provide the full CA certificate chain here.
Test the connection
1
Once your connection information is plugged in, click the “Connect to database” button. PlanetScale will attempt to connect to your database. If successful, you’ll see a green checkmark with a success message.
NoteIf your database uses foreign key constraints, we will detect them after successfully connecting to your external database and automatically enable foreign key constraint support for your database.
2
If the connection is successful, click “Begin database import” to start migrating your data to PlanetScale.
Foreign key constraints
If your database uses foreign key constraints, we will detect them after successfully connecting to your external database and automatically enable foreign key constraint support. There are a couple of important things to know about doing database imports with foreign key constraints:- We recommend importing using a replica: The foreign key constraint-specific import process holds a long-run transaction on the source database. This might cause an increased load on the source database. As a result, we recommend that users connect to a replica when importing their database.
- Import retries: If your import fails, the import must start from the beginning again. This is unlike other imports, where we retry from where we left off.
Import process
There are three simple steps to the database import process. You can cancel the import anytime by clicking “Cancel import” in the top right corner. If you cancel, we’ll delete all connection information.NoteDo not execute DDL (Data Definition Language) statements,
CREATE
, DROP
, ALTER
, TRUNCATE
, etc., on either database during the import process. Schema changes are not replicated between databases in either direction.Step 1: Copying schema and data

read-only
mode.
While in read-only
mode, you’re already able to take advantage of PlanetScale features such as:
- You can generate a password to connect to your new database in a MySQL client or in your application locally by clicking the “Connect” dropdown underneath the import flow.
- You can also view Query Insights, branches, and database settings by clicking around in the top nav.
Step 2: Replica mode

NoteIf you gave your PlanetScale database a different name than the one you’re importing from, ensure your application references the correct name.
Step 3: Primary mode

NoteIn Primary mode, any writes made directly to the external database will not be replicated to the PlanetScale database. Your application should be connected directly to the PlanetScale database.
Import complete
Your database has been fully imported into PlanetScale and is ready to use! Next, you’ll be taken to your database dashboard page. If you click on “Branches,” you’ll see that you now have one production branch,main
, that contains all of the data from your external database. Production branches are highly available and have optional additional protections, such as safe migrations, to prevent downtime.
Next steps
You just fully migrated your database to PlanetScale with no downtime and no fear of data loss. So what’s next? Here are some next steps you can take with your database:- Connect to your application — If you haven’t already, you can also connect to your application locally.
- Enable safe migrations — To protect your database from accidental schema changes an enable zero-downtime migrations, it is highly recommended to enable safe migrations on your new production branch.
- Create a development branch — Add PlanetScale to your development workflow with our powerful branching feature. You can branch off of your
main
branch to test schema changes in development and then merge them into production with our non-blocking schema change workflow. Again, no downtime! - Create a deploy request — Once your branch is in production, you can safeguard against unwanted or accidental changes by creating a development branch off of your production branch. This is where you can test out schema changes or any modifications you need to make. Once it’s ready, you can create a deploy request that your team can review before deploying to production.
Import limitations
PlanetScale will automatically stop the import process and detach your external database after 7 days of no activity once the initial import is finished. This will not impact your PlanetScale database created for the import, but it will stop all replication into and out of it.Troubleshooting
The following section covers common issues and compatibility limitations you may encounter during the import process. You should also check out our general MySQL compatibility guide.Connectivity issues
If you’re running into issues connecting with a username and password, try to plug that same connection information into the MySQL CLI or a MySQL GUI. Below is the command for the MySQL CLI.Host can’t target a PlanetScale database
The importer can not be used to duplicate a database already hosted on PlanetScale. If you need to copy or move a database between PlanetScale organizations, we recommend dumping the origin database and restoring that dump to a new database with the same name in the new organization. You can use thepscale database dump
and restore-dump
commands of our CLI application pscale to create and restore those dumps.
Compatibility issues
PlanetScale’s Vitess product gives us the power to perform data migrations at scale. This does, however, come with some trade-offs that could cause you to run into errors while importing an existing database. We believe these small trade-offs are worth the massive benefits, such as unlimited scaling through horizontal sharding, non-blocking schema changes, branching, and more. So, if you encounter compatibility issues while importing your external database to PlanetScale, we’d like to help you troubleshoot. Below are a few common errors you may encounter while importing or connecting to an external database. If you’re still having trouble importing, please feel free to reach out to support for additional assistance.No unique key
PlanetScale requires that all tables have a unique, not-null key. When you modify a table, both the old and the new schema must have a unique key as described, and the columns covered by those keys must exist in both the old and the new schema. If you run into this error, read through our Changing unique keys documentation for more information. It may also help to check out the official MySQL documentation about Primary Keys.Invalid charset
PlanetScale supports the following charsets:utf8
, utf8mb4
, utf8mb3
, latin1
, and ascii
.
If your table uses any other charset, please consult the official MySQL documentation about charsets.
Table names with special characters
Tables named with characters outside of the standard ASCII set are not supported. These tables may cause the import process to fail during the “Copying schema and data” phase of the import, resulting in a generic message stating that something went wrong. If any of your table names include special characters, they must be renamed before the import succeeds.Views
Views will not be imported or re-created on import. These views though can be created after a successful import completes.Unsupported feature
You might see this error if your table requires a storage engine other thanInnoDB
.
Please consult the official MySQL documentation about alternative storage engines for more information.
Server configuration issues
To ensure that we can migrate your data to PlanetScale with zero downtime, we check your database for some required configuration values, as described below:Variable | Required Value | Documentation |
---|---|---|
gtid_mode | ON | Documentation |
binlog_format | ROW | Documentation |
binlog_row_image | FULL | Documentation |
expire_logs_days * | > 2 | Documentation |
binlog_expire_logs_seconds * | > 172800 | Documentation |
expire_logs_days
or binlog_expire_logs_seconds
is set to a valid value. If both of these values are set, the value of binlog_expire_logs_seconds
takes precedence over expire_logs_days
.
Import user account issues
Please follow the Import tool user requirements guide to ensure that the database user performing the import has the correct set of grants and permissions on the external database.MySQL error number 1045: Access denied
If you get MySQL error number 1045; Symbol: ER_ACCESS_DENIED_ERROR; SQLSTATE: 28000. For example, with a message like:Message: Access denied for user '%s'@'%s' (using password: %s)
. You should check your MySQL grants and permissions.
When importing a database with foreign key constraints, we try with FLUSH TABLES WITH READ LOCK
. If we get a permission error, we resort to an explicit LOCK TABLES ...
statement. You will get the above error if both permissions are unavailable.
Ideally, the username will have FLUSH_TABLES
or RELOAD
privileges, but if not possible, then LOCK TABLES
at minimum.