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:
-
Add MySQL stack item to your application stack by selecting it from a large list of components.
-
Create a database in the config tab of the stack item after launching your application.
-
Install MySQL Workbench to manage the database and create a connection using the hostname and port provided.
-
Connect your PHP application to the database using the provided code snippet.
-
Push your code to the GIT repository and run the deploy scenario to access your application.
Add MySQL stack item
-
First you have to add the MySQL stack item to your application stack.
-
Navigate to your application stack and click the cog wheel to edit the stack.
- 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.
- Use the search to easily find “MySQL” and select the variation of your choice.
- Now select the resources to give to your database instance.
- 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.
- 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.
- 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 (Config
→ Variables
).
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
-
Downloaded MySQL Workbench from the Oracle website.
-
Open MySQL Workbench.
-
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 Config
→ Ports
.
-
Go back to the DeltaBlue web UI
-
Navigate to
Config
→Ports
. -
Enable remote access with the “remote access” toggle next to the MySQL stack item.
-
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.
-
The username and password can be found in the
Variables
tab. -
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.
- 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";
?>
-
Push your code to your GIT repository.
-
Link your git repository to your application and create a deploy scenario as described in .
-
Execute the deploy scenario and wait for it to finish running.
-
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”!