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.
This feature is currently in Limited Beta.
You must be an Organization Administrator to use this feature.
Before you begin, it may be helpful to check out our general MySQL compatibility guide.
To import an existing database into PlanetScale:
Head to your PlanetScale dashboard and click on "New database" > "Import database," which will bring you to the Import Setup page.
Give your imported database a name and select a region from the dropdown.
Add a credit card to your organization. You will only be charged if your import requires a Scaler plan (for imports that use over 5 GB of storage), and we will ask you to confirm before proceeding.
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.Note
Importing a database will not count towards your
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
- 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
- Username — The user's username used to connect to the database. This user must have
You must have binary logs enabled on the database you're importing.
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
writeaccess 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
From here, you can proceed to testing the connection or click "Show advanced settings" for more options.
(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.
For more information about certificates from a Certificate Authority, check out our Secure connections documentation.
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.Note
If your database uses foreign key constraints, we will automatically detect them after successfully connecting to your external database. We will ask you to accept the Terms of Service for the beta feature to continue the import process. Learn more details about importing with foreign key constraints below.
If the connection is successful, beta features are accepted (if you have foreign key constraints), or plan upgrades are complete (if the database is over 5 GB), click “Begin database import” to start migrating your data to PlanetScale.
Or, if the connection fails, you'll get an error message in the dashboard. Double-check your connection information or see our Troubleshooting section for more information.
If you're importing a large database (that uses over 5 GB of storage) and are on the Hobby plan, you will receive a prompt to upgrade your plan. You can use the Add new card button to add a credit card and upgrade your account.
Once you've successfully upgraded your plan, you should be able to continue importing your external database into PlanetScale.
Foreign key constraints are currently supported by PlanetScale in beta. You can read more in the foreign key constraints documentation.
If your database uses foreign key constraints, we will automatically detect them after successfully connecting to your external database. We will ask you to accept the Terms of Service for the beta feature to continue the import process.
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.
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.
Do not execute DDL (Data Definition Language) statements,
TRUNCATE, etc., on either database during the import process. Schema changes are not replicated between databases in either direction.
During this phase, the data and schema from your external database are imported into your PlanetScale database. The PlanetScale database is 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.
Once the initial import has finished, your PlanetScale database will be in Replica mode.
In this mode, your external database is the primary, but PlanetScale will directly read and write to the appropriate database. Connect your live application to the PlanetScale database and ensure it is fully compatible with your app.
If you gave your PlanetScale database a different name than the one you're importing from, ensure your application references the correct name.
Queries sent to PlanetScale will be served directly from the PlanetScale database. However, writes will be routed back to your external database, and their results will be replicated back to PlanetScale to keep both databases in sync. Behind the scenes, we're using Vitess's powerful Schema Routing rules to allow your PlanetScale database to act as a "data router."
We'll continue watching your external database and automatically update your PlanetScale database with any changes using Binary Log File Replication. In other words, any writes made directly to your external database will also appear in your PlanetScale database. This ensures you won't experience any data loss while updating your application's connection string to point at PlanetScale. For example, if a user makes a new comment on your blog application during this stage of the import, the comment will be written to both databases, no matter which database the application was pointed to. This ensures you won't experience any data loss while going through the import process or if you decide to cancel the import into PlanetScale.
Once you're ready for PlanetScale to become your primary database, click "Enable primary mode" to move to the next stage.
During this stage, PlanetScale replaces your external database as the primary database. It will serve both reads and writes. Behind the scenes, we essentially reverse the direction of the routing in the previous step. All reads and writes will go straight to the PlanetScale database. Updates will be replicated back to your external database.
In the blog application example context, if a user makes a new comment, the comment will be written to the PlanetScale database first and then copied back to your external database. Why copy it back? If you decide to cancel the import and switch back to your external database, you can be confident that you didn't lose any new or changed data while going through the import process.
In 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.
If you're happy with everything and ready to fully switch over, click the "Finish import" button to finalize the import.
When you finalize the import, we will detach your external database. The connection to that database will be closed, and all connection information will be deleted from PlanetScale. This will also cut off replication, so your PlanetScale database will no longer update your external database.
Your database has been fully imported into PlanetScale and is ready to use!
Next, you'll be taken to your database overview 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.
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
mainbranch 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.
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.
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.
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.
mysql -u <USERNAME> -p <PASSWORD> -h <HOST> -P <PORT> -D <DATABASE>
If the connection works there but not on PlanetScale, please reach out for additional assistance.
PlanetScale is built on Vitess, which 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.
PlanetScale requires that all tables have a unique, not-null key that remains unchanged during the migration. If you run into this error, read through our Change single unique key documentation for more information.
It may also help to check out the official MySQL documentation about Primary Keys.
PlanetScale supports the following charsets:
ascii. If your table uses any other charset, please consult the official MySQL documentation about charsets.
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.
You might see this error if your table requires a storage engine other than
InnoDB. Please consult the official MySQL documentation about alternative storage engines for more information.
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:
* PlanetScale requires that either
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
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.
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
RELOAD privileges, but if not possible, then
LOCK TABLES at minimum.
To check what your database server currently has these values set to, run the following query in a MySQL console connected to your database server:
SHOW VARIABLESWHERE Variable_Name LIKE '%gtid_mode'OR Variable_Name LIKE '%binlog_format'OR Variable_Name LIKE '%expire_logs_days'OR Variable_Name LIKE '%binlog_expire_logs_seconds';
Cross-check these values with the table above and update if needed.
If you see an error when querying your PlanetScale database after the initial import that looks like this:
ERROR 1105 (HY000): keyspace importkeyspace fetch error: node doesn't exist: [...]
This means the import process is underway, and this error should clear in 10-15 minutes after some additional processing by PlanetScale. If it does not, contact our PlanetScale support team, and we will help troubleshoot the issue.