Brands
Discover
Events
Newsletter
More

Follow Us

twitterfacebookinstagramyoutube
Youtstory

Brands

Resources

Stories

General

In-Depth

Announcement

Reports

News

Funding

Startup Sectors

Women in tech

Sportstech

Agritech

E-Commerce

Education

Lifestyle

Entertainment

Art & Culture

Travel & Leisure

Curtain Raiser

Wine and Food

YSTV

ADVERTISEMENT
Advertise with us

Tutorial: Accessing MySQL Data Service on Cloud Foundry through Tunneling

Tutorial: Accessing MySQL Data Service on Cloud Foundry through Tunneling

Monday August 13, 2012 , 3 min Read

Cloud Foundry is an Open PaaS supporting many languages, runtimes, frameworks and services. Cloud Foundry exposes MySQL, PostgreSQL, MongoDB, RabbitMQ and Redis as services that offer the database and messaging capabilities. Developers can easily bind the applications to one of these services during the deployment.

For a detailed walkthrough on getting started with Cloud Foundry, you can refer to the tutorial that we published (Part 1, Part 2 and Part 3) on CloudStory.in a while ago.

After you point vmc to a specific Cloud Foundry target, typing vmc services will show you the available services. For example, after targeting http://api.cloudfoundry.com, vmc services will show the following.

[crayon language="shell"]

vmc services

[/crayon]


During the deployment, Cloud Foundry asks if you want to bind the application to any of the services. Once you choose a specific service, it can be accessed during the runtime through the VCAP_SERVICES environment variable. But many times, developers need to access the services like MySQL, PostgreSQL and MongoDB directly to manage the database. This is where Cloud Foundry tunneling comes into the picture. In this tutorial, we will access MySQL from the local machine through the popular MySQL Workbench.

First, let us make sure that the MySQL data service is provisioned for us. We can check this by typing vmc services and looking under the provisioned services.


Now, let’s install the Caldecott gem to enable tunneling. Caldecott is a simple Ruby gem that enables port forwarding on the local machine.

[crayon language="shell"]

gem install caldecott

[/crayon]


With Caldecott in place, it’s time for us to create the tunnel. We do this by typing vmc tunnel.

[crayon language="shell"]

vmc tunnel

[/crayon]

Note that this command shows the provisioned services. After we select that, the next step is to choose the mysql tool that can be invoked directly by the tool.

If the mysql command line is in path, choosing option 2 will launch it with appropriate parameters. But by choosing 1, we will able to use any tool that can connect to MySQL In this case, we will use MySQL Workbench.


Launch MySQL Workbench and click on New Server Instance under Server Administration.


Select Remote Host and enter 127.0.0.1. Do not enter the port number at this point.


In the next step, enter the port number that vmc tunnel has shown followed by the username and password.


Click continue to see the confirmation.


Finally, double clicking on the server will launch the query editor.




Now, you can run queries and perform any operations on the database provisioned at CloudFoundry.com.

- Janakiram MSV, Chief Editor, CloudStory.in