Skip to content

Tutorial: Importing a database

The goal of this tutorial is to migrate a non-Elastycloud database to the Elastycloud platform.

Warning

This tutorial will wipe your deployments database and replace it with your own database. It is highly recommended that you try this out on a staging deployment first. This is not an officially supported feature yet, you may encounter issues during this guide that is specific to your case, leaving your deployment in a failed state.

Prerequisites

  1. You have to be a registered partner of Elastycloud.
  2. You need to have an account and be able to sign in to the Elastycloud Console.
  3. You need to have an existing deployment up and running.
  4. You need to have your own package running on the store.
  5. You need to have a local installation of the above package running, so that you can prepare a database dump.
  6. You need to have the toolkit deployed.

Tutorial

It is important, in order for the site to work after an import, that the database dump is taken from a codebase that is exactly the same as the one that is currently deployed.

A Magento 2 database export will contain DEFINERs that reference old MySQL credentials (e.g. DEFINER=root@localhost). These references have to be removed from the exported database file before proceeding, as they will not match the credentials used on the Elastycloud platform. If they are not removed, the import will fail.

You can do this one of two ways:

If you are creating a fresh database export:
mysqldump ... | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > fresh-db-export.sql

If you have an existing database export:
sed -i 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' existing-db-export.sql

Preparing for the database import

Make note of your Elastycloud domain name

In the Elastycloud Console TODO: Finish this.

Increase the toolkit lifetime

Inside of the toolkit panel, increase the toolkit lifetime in the top right corner of the page, to ensure that there is enough time to perform the import.

Save your Elastycloud configuration data

  1. Open the toolkit UI, and press Database ‣ PhpMyAdmin in the menu on the left.
  2. In the appropriate database, go to the core_config_data table.
  3. Press Export in the menu along the top of the page.
  4. Use the default settings and save the SQL file by pressing Go.
  5. Verify that the resultant SQL file contains valid SQL data.
  6. Repeat these steps for the elastycloud_domainmanager_domain, elastycloud_domainmanager_domain_assignment, and elastycloud_ftp_accounts tables as well.

Import the database

Warning

The following steps will render your deployment broken until the entire import is completed.

Danger

Remember to disable foreign key checks when importing a database. Not doing so may lead to looping and unwanted behavior.

  1. Open the toolkit UI, and press Database.
  2. Select the appropriate database on the left; the main view will be filled with a list of tables.
  3. Scroll all the way to the bottom, select Check all.
  4. To the right of Check all, open the dropdown menu and find DROP.
  5. On the following page, press Yes. Completing this may take a while.
  6. Open the Import tab from the menu along the top.
  7. Press Choose file and select your complete gzipped Magento 2 database export.

Make certain that the dump has been cleaned of DEFINERs, and make absolute certain to uncheck Enable foreign key checks.

Note

The PhpMyAdmin frontend may timeout (error 504) during long imports, but the import will keep working in the background.

Restore base URL

  1. Once again, find the database table core_config_data and open the Search from the menu along the top of the page.
  2. Leave everything on the default settings, and enter http% in the field labeled value.
  3. Update the entries according to the values you exported during the preparations. Make sure to include https://and a terminating slash. E.g. https://www.your-domain.com/
  4. Make sure that the path admin/url/custom is set to the same value as the one you saved during the preparations.
  5. Make sure that the path admin/url/use_custom is set to 1.
  6. Import the data from the elastycloud_domainmanager_domain, elastycloud_domainmanager_domain_assignment, and elastycloud_ftp_accounts tables you exported during the preparations.

Restore asset management settings

Warning

These settings must match the ones specified in your elastycloud.yaml file in the root of your repository. If you have not made any changes, you can safely use the defaults below.

Delete all asset management settings from core_config_data by running this query:

DELETE FROM `core_config_data`
WHERE `path` IN (
   "dev/css/merge_css_files",
   "dev/css/minify_files",
   "dev/js/enable_js_bundling",
   "dev/js/merge_files",
   "dev/js/minify_files",
   "dev/static/sign"
)

Add the corrent values by running the following query:

INSERT INTO `core_config_data`
    (scope,scope_id,path,value)
VALUES
    ("default","0","dev/css/merge_css_files","1"),
    ("default","0","dev/css/minify_files","1"),
    ("default","0","dev/js/enable_js_bundling","1"),
    ("default","0","dev/js/merge_files","1"),
    ("default","0","dev/js/minify_files","0"),
    ("default","0","dev/static/sign","1");