Skip to main content

MySQL

Creating a MySQL database

To create a MySQL database in the mStudio, follow these steps:

  1. Navigate to the project that you want to create the database in.
  2. Select the "Databases" menu item in the sidebar.
  3. Click the "Create Database" button and select "MySQL".
  4. Enter a description for the database, select the desired version and choose a password for the database user.

After the installation has completed, observe the host and port in the details under connection information. You need both for the configuration of your system.

Operational concerns

Managed backup and recovery

The mittwald cloud platform automatically creates backups of your projects and their databases at regular intervals. You can inspect the available backups as any time using the mStudio UI or the mw CLI, using the mw backup list command. You can also create a backup manually using the mw backup create command:

Local shell session
$ mw backup create --wait --expires 30d

To recover the contents of a single MySQL database, you can follow the following steps:

  1. Download a backup to your local machine:

    Local shell session
    $ mw backup download <backup-id> --format tar --output backup.tar.gz
  2. After downloading the backup, you can extract the database contents from the downloaded archive:

    Local shell session
    $ database_id=<database-id>
    $ tar xfz backup.tar.gz dbdump-${database_id/_/-}
  3. Recover the backup using the mw database mysql import command. For this, you need to have an SSH key set up on your local machine, which is also linked to your mStudio user account.

    Local shell session
    $ database_id=<database-id>
    $ mw database mysql import ${database_id} --input dbdump-${database_id/_/-}/*.sql.gz --gzip

Manual backup and recovery

You can use the mw CLI to manually create (and restore) backups of your MySQL database. As a prerequisite, you need to have an SSH key set up on your local machine, which is also linked to your mStudio user account.

To create a backup, run the following command:

Local shell session
$ mw database mysql dump <database-id> --output dump.sql.gz --gzip

In this command, replace <database-id> with the ID of the MySQL database you want to back up. The --gzip flag compresses the backup file, which can save disk space and reduce transfer times.

To restore a backup, run the following command:

Local shell session
$ mw database mysql import <database-id> --input dump.sql.gz --gzip