Overview

This guide shows you how to export a database of a Beach instance to a file, import an existing MariaDB or MySQL database dump into a Beach instance and an easy way to clone a whole instance database into another instance.

You need SSH access to the respective instance you want to export from or import into. A MariaDB client or any other software is not required on your local machine.

Export an Instance Database

Connect to your instance via SSH, for example by using the SSH command shown in the instance connection details. The shell is preconfigured with the instance's database username, password and host (in my.cnf) and the database name is available via an environment variable.

Therefore all you need to do is running the following command:

You now have a database dump in the file database.sql. You can download this file using scp or by moving it into the public Web folder and downloading it via a web browser (be careful, choose a different name for a file and remove it directly after download).

Tip: You can use the command bat (instead of cat or less) to display the database.sql in your terminal. Bat makes viewing of these files easier, as it provides syntax highlighting and some other convenient features.

Import an Instance Database

You can import data from an existing database dump from an .sql file. There are two easy ways to upload such a file into your instance:

  • use scp or an SSH client to connect to your instance and upload the file
  • log into your instance via SSH and download the file from a public URL using wget or curl

Once you have the database dump file in your instance, you can import it using the mysql client. Username, password, host and database name are preconfigured for your instance shell:

Depending on your database dump (for example, if it contains DROP TABLE statements), you will need to empty the existing database before importing new data. In any case, be careful, and if in doubt, better create a backup before you proceed.

Copy a Database from one Instance to Another

You can also directly pipe a database dump into another database, skipping the step of creating a file, and downloading and uploading it.

For that you need to look up the following data of the target instance:

  • database server hostname
  • database name
  • database username
  • database password

As mentioned in "Import an Instance Database", you might need to prepare the target database, by removing existing data.

When you are ready, log into your source instance via SSH and run the following command: