问题
I have a Spring Boot
based REST
application that is deployed on Pivotal Cloud Foundry (PCF)
and working fine. But this REST application did not had any DB connection till now. Hence, I decided to install MySQL
service on PCF
from the marketplace and finally got it bounded to my application successfully.
However, the problem is that I am NOT able to connect to this newly created MySQL
instance via CLI
or any other GUI
.
So far I have followed following links but no luck.
- https://docs.pivotal.io/pivotalcf/2-4/devguide/deploy-apps/ssh-services.html
- How to setup mysql develper for PCF mySQL database to manage it
The steps that I performed in order to accomplish this are:
- Created service instance for
MySQL
successfully Bound the service instance for
MySQL
to the application successfully (see thecf service
s command result above)# cf services
name service plan bound apps last operation
my-mysql-db cleardb spark agrisell-rest-app create succeeded
Pushed my app successfully and can hit the
REST API
successfullyhttps://agrisell-rest-app.cfapps.io/hello
Enabled
ssh
on the host app usingcf enable-ssh agrisell-rest-app
successfullyCreated service key using
cf create-service-key my-mysql-db my-mysql-db-service-key
(the command for fetching service keys after creation is shown below)# cf service-keys my-mysql-db
name my-mysql-db-service-key
Retrieved service key and DB credentials using following command
cf service-key my-mysql-db my-mysql-db-service-key
{
"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"
}
Configured
SSH
tunnel successfullycf ssh -L 63306:us-cdbr-iron-east-01.cleardb.net:3306 agrisell-rest-app
Accessing the service instance through
CLI
vcap@33eb3942-10bd-4068-650f-64fc:~$ mysql -u hello123 -h 0 -p -D ad_b509d7f388732d5 -P 63306 bash: mysql: command not found
Based the above error it felt to me as if did not install the mysql plugins correctly but I already have them installed.
# 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.
Second Approach:
Second approach I tried was to connect to the PCF MySQL DB
through MySQL Workbench
which comes bundled with MySQL
server installation on Windows
.
I use it to connect to my local MySQL DB
. I modified the settings to point it to the host, db and changed credentials and tried to connect which did not work either.
Third Approach
Third approach that I tried was installing Pivotal MySQL Web Database Management
tool which I from one of the PCF
documentation
https://docs.pivotal.io/p-mysql/2-2/use.html#mysqlweb
I installed it on my Windows 10
machine (did not deploy it to PCF
) and tried to log in but that also failed.
Second Approach Tried and Failed
Based on your response Arun, I followed all the instructions mentioned in the Readme here (https://github.com/pivotal-cf/PivotalMySQLWeb) but it does not allow me to login to the application with DB URL and credentials. The first login with credentials admin/cfmysqlweb
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.
Deployed the PivotalMysqlWeb on PCF and bound it to DB instance
Login Page that shows up now after basic authentication is successful using admin/cfmysqlweb credentials
DB credentials entered above and on submit I am taken back to the first login page (Back to square one)
回答1:
You cannot connect with any of the Marketplace service
with the tools that you have in your PC / Laptop (like what you do with MySQL App)
The reason is that any Marketplace service within PCF can be running anywhere and you are just provided an instance
of it .
For security purpose, your Marketplace service (that you ordered .. that you paid) is just exposed only to that particular PCF Foundation
..
If you still want to connect to MySQL and have a look at your database, I recommend you to use PivotalMySQLWeb tool . You would have to upload this App in the same PCF-space
and bind it to your MySQL DB Instance
that you would have created in that space
. You can view lot of instructions in their README file
回答2:
I installed MySQL Workbench and created a new connection. Then filled in the details from the service details on PCF (the ones you posted)
{
"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"
}
So in your case:
host: us-cdbr-iron-east-01.cleardb.net
Username: hello123
Password: world456
default Schema: ad_b509d7f388732d5 Port: 3306
Interesting to note, the default schema need to match the "name" attribute. I put a custom name and couldn't connect. Not super sure why, but what can you do.
回答3:
In case anyone wants to connect aws-rds-mysql (instantiated from Pivotal Cloud Foundry) from IntelliJ, here are the steps:
Once you have created ssh tunnel, you can access the AWS-RDS database from your localhost on port 63306, follow the instructions in order to connect DB with DB Navigator plugin (intelliJ )
- Install DB Navigator plugin in intelliJ (Community Edition), if you have't installed already -> https://plugins.jetbrains.com/plugin/1800-database-navigator
- Connect to AWS RDS in intelliJ -> notice the connection is made via
localhost on port 63306
- Go to DB Navigator plugin and click on custom under new connection.
- Enter the URL as: jdbc:mysql://:@localhost:63306/<database_name>
Steps are also available at GitHub
来源:https://stackoverflow.com/questions/54284031/how-do-i-connect-to-my-mysql-service-on-pivotal-cloud-foundry-pcf-via-mysql-wo