title: How do I connect to my MySQL service on Pivotal Cloud Foundry (PCF) via MySQL Workbench or CLI or MySQLWeb Database Management App?
body: <p>I have a <code>Spring Boot</code> based <code>REST</code> application that is deployed on <code>Pivotal Cloud Foundry (PCF)</code> and working fine. But this REST application did not had any DB connection till now. Hence, I decided to install <code>MySQL</code> service on <code>PCF</code> from the marketplace and finally got it bounded to my application successfully. </p>
  
  <p>However, the problem is that I am NOT able to connect to this newly created <code>MySQL</code> instance via <code>CLI</code> or any other <code>GUI</code>. </p>
  
  <p>So far I have followed following links but no luck.</p>
  
  <ul>
  <li><a href="https://docs.pivotal.io/pivotalcf/2-4/devguide/deploy-apps/ssh-services.html" rel="nofollow noreferrer">https://docs.pivotal.io/pivotalcf/2-4/devguide/deploy-apps/ssh-services.html</a></li>
  <li><a href="https://stackoverflow.com/questions/49313213/how-to-setup-mysql-develper-for-pcf-mysql-database-to-manage-it">How to setup mysql develper for PCF mySQL database to manage it</a></li>
  </ul>
  
  <p>The steps that I performed in order to accomplish this are:</p>
  
  <ol>
  <li>Created service instance for <code>MySQL</code> successfully</li>
  <li><p>Bound the service instance for <code>MySQL</code> to the application successfully (see the <code>cf service</code>s command result above)</p>
  
  <p><strong># cf services</strong></p>
  
  <p>name                    service          plan       bound apps          last operation</p>
  
  <pre><code>my-mysql-db             cleardb          spark      agrisell-rest-app   create succeeded
  </code></pre></li>
  <li><p>Pushed my app successfully and can hit the <code>REST API</code> successfully</p>
  
  <p><a href="https://agrisell-rest-app.cfapps.io/hello" rel="nofollow noreferrer">https://agrisell-rest-app.cfapps.io/hello</a></p></li>
  <li><p>Enabled <code>ssh</code> on the host app using <code>cf enable-ssh agrisell-rest-app</code> successfully</p></li>
  <li><p>Created service key using <code>cf create-service-key my-mysql-db my-mysql-db-service-key</code> (the command for fetching service keys after creation is shown below)</p>
  
  <p><strong># cf service-keys my-mysql-db</strong></p>
  
  <p>name
  my-mysql-db-service-key</p></li>
  <li><p>Retrieved service key and DB credentials using following command</p></li>
  </ol>
  
  <p><strong>cf service-key my-mysql-db my-mysql-db-service-key</strong> </p>
  
  <pre><code>{
   "hostname": "us-cdbr-iron-east-01.cleardb.net",
   "jdbcUrl": "jdbc:mysql://us-cdbr-iron-east-01.cleardb.net/ad_b509d7f388732d5?user=hello123\u0026password=world456",
   "name": "ad_b509d7f388732d5",
   "password": "world456",
   "port": "3306",
   "uri": "mysql://b311794a3c31eb:ca7ad71f@us-cdbr-iron-east-01.cleardb.net:3306/ad_b509d7f388732d5?reconnect=true",
   "username": "hello123"
  }
  </code></pre>
  
  <ol start="7">
  <li><p>Configured <code>SSH</code> tunnel successfully</p>
  
  <p>cf ssh -L 63306:us-cdbr-iron-east-01.cleardb.net:3306 agrisell-rest-app</p></li>
  <li><p>Accessing the service instance through <code>CLI</code></p>
  
  <p>vcap@33eb3942-10bd-4068-650f-64fc:~$ mysql -u hello123 -h 0 -p -D ad_b509d7f388732d5 -P 63306
  bash: mysql: command not found</p></li>
  </ol>
  
  <p>Based the above error it felt to me as if did not install the mysql plugins correctly but I already have them installed. </p>
  
  <pre><code># cf plugins
  Listing installed plugins...
  
  plugin   version   command name   command help
  mysql    2.0.0     mysql          Connect to a MySQL database service
  mysql    2.0.0     mysqldump      Dump a MySQL database
  
  Use 'cf repo-plugins' to list plugins in registered repos available to install.
  </code></pre>
  
  <p><strong>Second Approach:</strong></p>
  
  <p>Second approach I tried was to connect to the <code>PCF MySQL DB</code> through <code>MySQL Workbench</code> which comes bundled with <code>MySQL</code> server installation on <code>Windows</code>.
  I use it to connect to my local <code>MySQL DB</code>. I modified the settings to point it to the host, db and changed credentials and tried to connect which did not work either.</p>
  
  <p><strong>Third Approach</strong></p>
  
  <p>Third approach that I tried was installing <code>Pivotal MySQL Web Database Management</code> tool which I from one of the <code>PCF</code> documentation</p>
  
  <pre><code>https://docs.pivotal.io/p-mysql/2-2/use.html#mysqlweb
  </code></pre>
  
  <p>I installed it on my <code>Windows 10</code> machine (did not deploy it to <code>PCF</code>) and tried to log in but that also failed. </p>
  
  <p><strong>Second Approach Tried and Failed</strong></p>
  
  <p>Based on your response Arun, I followed all the instructions mentioned in the Readme here (<a href="https://github.com/pivotal-cf/PivotalMySQLWeb" rel="nofollow noreferrer">https://github.com/pivotal-cf/PivotalMySQLWeb</a>) but it does not allow me to login to the application with DB URL and credentials. The first login with credentials <code>admin/cfmysqlweb</code> works but the login page where it requires DB credentials and password it send me back to the first login screen with a message "Bad Credentials". Screenshot below.</p>
  
  <p><strong>Deployed the PivotalMysqlWeb on PCF and bound it to DB instance</strong></p>
  
  <p><a href="https://i.stack.imgur.com/038l4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/038l4.png" alt="enter image description here"></a></p>
  
  <p><strong>Login Page that shows up now after basic authentication is successful using admin/cfmysqlweb credentials</strong></p>
  
  <p><a href="https://i.stack.imgur.com/0qTLB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0qTLB.png" alt="enter image description here"></a></p>
  
  <p><strong>DB credentials entered above and on submit I am taken back to the first login page (Back to square one)</strong></p>
  
  <p><a href="https://i.stack.imgur.com/1LSDt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1LSDt.png" alt="enter image description here"></a></p>