cloudfoundry-samples / cf-sample-app-spring

Introduction to Cloud Foundry app deployment and management concepts.
31 stars 142 forks source link

How to successfully connect to my local MySQL 8.0 database from my Spring Boot application pushed to my local PCF DEV ? #20

Closed ranadeep-sh closed 5 years ago

ranadeep-sh commented 5 years ago

My app [gs-spring-boot.zip] is unable to connect to the locally running MySQL 8.0 database after carrying out the following configurations as described in various tutorials online.

Please find the errors in the attached log file named [cf_spring_boot_log.txt]

Please find a screenshot of the MySQL account with same credentials as configured below. Local-MySQL-account

PS C:\WINDOWS\system32> cf login -a https://api.dev.cfdev.sh --skip-ssl-validation -u admin -p admin

PS E:\> cf cups rana-db -p '{\"username\": \"pcfusername\", \"password\": \"pcfpassword\", \"name\": \"world\", \"hostname\": \"127.0.0.1\", \"port\": 3306, \"uri\": \"mysql://pcfusername:pcfpassword@127.0.0.1:3306/world\", \"jdbcUrl\": \"jdbc:mysql://127.0.0.1:3306/world?user=pcfusername&password=pcfpassword\"}'

PS E:\> cf push pcf-people-mgmt -p C:\complete\target\pcf-people-mgmt-1.0-SNAPSHOT.jar

PS E:\> cf bind-service pcf-people-mgmt rana-db

PS E:\> cf restage pcf-people-mgmt

I have spent weeks with no success. Please let me know what I am missing in my configuration.

dmikusa commented 5 years ago

You are setting \"hostname\": \"127.0.0.1\", in the user provided service which won't work. When your app runs it will get this value and try to connect to 127.0.0.1 which is the container itself, not your computer, where MySQL is actually running.

You need to put an actual routable IP for your hostname and you need to make sure that it's accessible from a container running on PCF Dev. To test, push an app, then cf ssh into the app and then just see if you can nc -v <hostname> 3306. If you get a message that says it established a TCP connection then you've found the right hostname.

Hope that helps!

ranadeep-sh commented 5 years ago

Thanks Daniel. You are awesome. Yes. It did work after using the DHCP-assigned IP Address while creating the user-provided service for the database.