MySQL Workbench and MySQL CLI Client

MySQL Workbench and MySQL CLI Client - How to connect them with a9s MySQL Services Blogpost Header

How to Connect Them with a9s MySQL Services

anynines recently released its a9s MySQL Data Service offering. Most of the developers use MySQL Workbench client for connecting to MySQL server. Now, let us walk down with all the required steps to connect our a9s MySQL service instances with MySQL Workbench and as well as MySQL CLI client in this blog post.

Prerequisites to Connect with a9s MySQL

To connect with a9s MySQL one needs to have the following prerequisites:

Tunneling with a9s MySQL Service

This is our first step to connect with a9s MySQL service. Here, we are creating a tunnel to a9s MySQL Data Service bounded with your_application hosted with a hostname as your_host_name. To obtain the hostname of a data service connected to an application, we need to use CF CLI command as shown and pick the hostname from the key-value pair called “host” as shown below:

$ cf env your_application

Getting env variables for app your_application in org your_user_org / space test as your_username...
OK

System-Provided:
{
 "VCAP_SERVICES": {
  "a9s-mysql101": [
   {
    "binding_name": null,
    "credentials": {
     "dns_servers": [
      "10.0.35.11"
     ],
     "host": "your_host_name",
     "hosts": [
      "your_one_of_the_hosts"
     ],
     "name": "database_name",
     "password": "mysql_password",
     "port": 3306,
     "uri": "mysql://mysql_username:mysql_password@database_name.your_host_name:3306/database_name",
     "username": "mysql_username"
    },
    "instance_name": "your_a9s_mysql_service",
    "label": "a9s-mysql101",
    "name": "your_a9s_mysql_service",
    "plan": "mysql-single-small",
    "provider": null,
    "syslog_drain_url": null,
    "tags": [
     "sql",
     "database",
     "object-relational",
     "consistent"
    ],
    "volume_mounts": []
   }
  ]
 }

Now, let us create a tunnel to our a9s MySQL service by using CF CLI command as shown.

$ cf ssh your_application -L 3306:your_host_name:3306

Replace your_application and your_host_name from the output obtained above with cf env command.

Connect with MySQL Workbench

After successful tunnel creation, please do test the connection and add it into your workbench with the following screenshots below step by step. This illustration is done using MAC OS.

  1. Fill Username section from the above cf env output section as shown below:
  2. Now, let us test the connection by filling in the password with mysql_password from the above cf env output section as shown below:
  3. After successfully testing the connection, you will be prompted with an output as shown below:
  4. Now, add this as a connection with your desired name into your connection list and also, make sure your tunnel is always connected in your terminal.

Connect with MySQL CLI Client

To connect with MySQL CLI Client after tunnel creation, just execute the below command as shown below:

$ mysql -u mysql_username -h 0 -p -D database_name -P 3306

In the above command, substitute mysql_username and database_name from the above cf env output section. Please do make sure that the tunnel is established in your terminal when you are accessing a9s MySQL services using MySQL CLI client.

Conclusion

A simple guide to setup various MysQL clients to our a9s MySQL Data Service. Hope you enjoyed the step by step tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *