Setting up your first database

This tutorial explains setting up a MySQL database on the DeltaBlue Cloud Platform.

To help you set up a database, this tutorial will guide you through these steps:

  1. Add MySQL stack item to your application stack by selecting it from a large list of components.

  2. Create a database in the config tab of the stack item after launching your application.

  3. Install MySQL Workbench to manage the database and create a connection using the hostname and port provided.

  4. Connect your PHP application to the database using the provided code snippet.

  5. Push your code to the GIT repository and run the deploy scenario to access your application.

Add MySQL stack item

  1. First you have to add the MySQL stack item to your application stack.

  2. Navigate to your application stack and click the cog wheel to edit the stack.

  1. Select “Add stack item”.

You can now select the component of your choice. As you can see we support a very large list of components.

  1. Use the search to easily find “MySQL” and select the variation of your choice.

  1. Now select the resources to give to your database instance.

  1. Confirm your choice.

You now have a MySQL stack item inside your application.

Create database

Now that the stackitem is in place, it is time to create the database.

In the config tab, a menu “MYSQL” has appeared, because you added the MySQL stack item.

  1. Click it.

In here, you can fill out a form add a new database to your MySQL stack item.

Your application must be launched in order to create a database. If it is not launched, click the launch button in the top right corner. This might take a minute.

  1. Fill in the credentials of your choice and click save.

After you have created the database, you can find the database related variables in the variables tab (ConfigVariables).

Managing your database

You now have a database setup on the DeltaBlue Cloud Platform. In order to manage the database you need database management software.

For this tutorial, we’ll guide you through the steps using Oracle MySQL Workbench. Of course you are free to use another tool of your choice, or use no tool at all.

This part of the tutorial is not necessary, but having a database management tool can definitly come in handy, so we’ll guide you through the steps in case you might need one.

Install MySQL Workbench

  1. Downloaded MySQL Workbench from the Oracle website.

  2. Open MySQL Workbench.

  3. Click on the + button next to “MySQL Connections”.

Creating a connection to your database

You need the hostname of the database. You can find the hostname in the DeltaBlue platform under ConfigPorts.

  1. Go back to the DeltaBlue web UI

  2. Navigate to ConfigPorts.

  3. Enable remote access with the “remote access” toggle next to the MySQL stack item.

  4. Copy the connection command by clicking the copy button.

It looks something like this:

mysql -h project123456.deltablue.io -P 33061

project123456.deltablue.io is the hostname and 33061 the port.

  1. The username and password can be found in the Variables tab.

  2. In MySQL Workbench, fill in these fields as follows:

When the connection information is correct, you can use the tool to manage your database. No further action is needed for this tutorial.

Testing your database setup

For a real application, there are a myriad of options to start using your database from your application code. To test if your setup works, we’ll guide you through a basic example, using PHP.

  1. Establish a connection to your database in your PHP application you can use the following snippet in a PHP file:
<?php
$servername = "127.0.0.1";
$username = "your-username";
$password = "your-chosen-password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
  1. Push your code to your GIT repository.

  2. Link your git repository to your application and create a deploy scenario as described in .

  3. Execute the deploy scenario and wait for it to finish running.

  4. With your browser, navigate to the platform url that is shown in the Details tab → Web access.

If everything is set up correctly, you should see “Connected successfully”!