I've developed an application using JSP, Spring Security, MySql. I deployed it on Cloudfoundry. But just war file and I binded mysql service. But I also have to configure MySQL database that consists of two tables, new user and it all in my own database. While i tested my application on localhost i prepared the database running manual scripts in MySQL command window.
Question: How can I make the same configurations in CloudFoundry? can I the same way run all commands and scripts manually or export the database somehow? if yes, how to do this. And what to write here now instead of localhost?
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/security_filter" />
thank you
Caldecott (vmc tunnel) is the correct way to access your cloudoundry database (for me it works and i am using ruby 1.8): http://docs.cloudfoundry.com/tools/vmc/caldecott.html
If that does not work for you you will have to do something manually (much harder):
Create a sample jsp/servlet application that connects to a mysql database (retrieving connection string, username and password as input from user). Then it will just run the sql statement against the database ( sql statement will be also input from user)
Bundle this application in your war
Now you have to retrieve database connection string/username and password. You can retrieve them from the enviromental variable VCAP_SERVICES. Just log log it in a startup listener (eg ServletContextListener)
Deploy your war and get logs from server (vmc logs ApplicationName). Get connection string, username and password
Logon to your application and use your database application to access the database using the db info you collected in the previous step
Just note that this is very dangerous approach. Just be sure to secure this database application or after the initial import remove it from your war and redeploy the application
As a final note you can check if such a database console application already exists so that you dont have to create your own (for example grails has a nice application for this http://grails.org/plugin/dbconsole. Maybe something exists for jsp/servlets)
Hope it helps if you have no luck with the ruby problem
You would need to create a mysqldump of your database.
Once you have the mysqldump file, you then use caldecott and perform vmc tunnel to your MySQL service. After you have establish a connection with your MySQL service on Cloud Foundry, you then need to use the mysql command to manually import the mysqldump file into your service.
For how to use vmc tunnel, visit the documentation site at: http://docs.cloudfoundry.com/tools/vmc/caldecott.html
Related
I am trying to understand PCF concepts and thinking that once i am done with creating mysql services in PCF, how i can manage that database like creating tables and maintaining that table just like we do in pur traditional environment using mySqldeveoper. I came across one service like PivotalMySQLWeb and tried but didnt liked it much. So if somehow i can get connection details of mysql service , i can use that to connect using sql developer.
The links #khalid mentioned are definitely good.
http://docs.pivotal.io/p-mysql/2-0/use.html
https://github.com/andreasf/cf-mysql-plugin#usage
More generally, you can use an SSH tunnel to access any service, not just MySQL. This also allows you to use whatever tool you would like to access the service.
This is documented here, but if for some reason that goes away here are the steps.
Create your target service instance, if you don't have one already.
Push an app, any app. It really doesn't matter, it can be a hello world app. The app doesn't even need to use the service. We just need something to connect to.
Either Bind the service from #1 to the app in #2 or create a service key using the service from #1. If you bind to the app, run cf env <app> or if you use a service key run cf service-key MY-DB EXTERNAL-ACCESS-KEY and either one will give you your service credentials.
Run cf ssh -L 63306:us-cdbr-iron-east-01.p-mysql.net:3306 YOUR-HOST-APP, where 63306 is the local port you'll connect to on your machine and us-cdbr-iron-east-01.p-mysql.net:3306 are the host and port from the credentials in step #3.
The tunnel is now up, use whatever client you'd like to connect to your service. For example: mysql -u b5136e448be920 -h localhost -p -D ad_b2fca6t49704585d -P 63306, where b5136e448be920 and ad_b2fca6t49704585d are the username and database name from step #3 and 63306 is the local port you picked from step #4.
Additionally, if you want to connect aws-rds-mysql (instantiated from Pivotal Cloud Foundry) from IntelliJ, you can use the DB-Navigator Plugin (https://plugins.jetbrains.com/plugin/1800-database-navigator) inside IntelliJ, through which, database manipulation can be performed.
After creating the ssh tunnel $ cf ssh -L 63306:<DB_HOSTNAME>:3306 YOUR-HOST-APP (as also mentioned in https://docs.pivotal.io/pivotalcf/2-4/devguide/deploy-apps/ssh-services.html),
Go to DB Navigator plugin and click on custom under new connection.
Enter the URL as: jdbc:mysql://:password>#localhost:63306/<database_name>
The following thread might be helpful for you as well How do I connect to my MySQL service on Pivotal Cloud Foundry (PCF) via MySQL Workbench or CLI or MySQLWeb Database Management App?
I am using JDBCRealm in TomEE 1.7.0 connecting to MySQL with this configuration
<Realm className="org.apache.catalina.realm.JDBCRealm"
digest="MD5"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/database"
connectionName="admin"
connectionPassword="pass"
userTable="USUARIO"
userNameCol="USUARIO"
userCredCol="PASSWORD"
userRoleTable="USUARIOROL"
roleNameCol="ROL" />
It works fine, but an external application inserts new users into database, so I cannot log in to my application with these new users, unless I restart TomEE but I want to avoid it... What can I do?
Apache Tomcat documentation says
Because the lookup is done each time that it is required, changes to the database will be immediately reflected in the information used to authenticate new logins.
... but I can't get the changes in database to log in with new users
I'm using form-based authentication with primefaces and JSF
Did you check you use this realm? Can it be a lockoutrealm side effect? This just does a request so either the db is not well inserting data or you dont use what you think
I created my scaled application on Openshift server with following command:
rhc app create MyApp jbossews-2.0 -s
Then add Mysql:
rhc cartridge add mysql-5.5 -a MyApp
My application using Struts2, Spring & Hibernate. I configured the datasource as follow:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/MysqlDS"/>
</bean>
The JNDI "MysqlDS" is defined in .openshift\config\context.xml with the connection url:
url="jdbc:mysql://5344d4de4382ec43c9000090-myapp.rhcloud.com:37941/mydb"
The problem is my scale app can not establish the connection to Mysql with an error:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect
3 times. Giving up.)
I'm sure the username & password to access the database is correct. It seem MySQL on Openshift server doesn't open its port. When I tried to use an external database on freemysqlhosting.net (with open host & port) the application run well. But I just want to use MySQL db on Openshift. Anyone who have experience on this please give me some suggestion. Thanks
Make sure that you restarted your application after adding the mysql cartridge, sometimes the environment variables don't show up correctly until you restart. Also try to ssh to your gear and see if you can use the "mysql" command to connect to your mysql database directly.
If you left the .openshift/config/context.xml unchanged, the JNDI name fore the MySQL datasource is actually jdbc/MySQLDS and not jdbc/MysqlDS.
This was changed some time ago.
The documentation here http://openshift.github.io/documentation/oo_cartridge_guide.html#tomcat-cartridge-integrations is unfortunately not correct.
total newbie and totally lost...
I'm trying to setup coldfusion(8) with a mysql(5.5) database on a local (apache 2.2) webserver running Windows XP.
Coldfusion and Apache are running, but I don't know how to fiddle this in with MySQL.
I'm doing the following:
- Import file1.sql and file2.sql into MySql workbench (5.2) by reverse engineering
- Save this new model as base.mwb into my Apache htdocs folder
- Open the Coldfusion Administrator Data Sources
- Add new Source "myName", Database "base", localhost, 3306, root, password
When I try to add I always get Unknown database 'base' error.
I also tried to make a connection in MySQL or set up a new server instance in MySQL workbench, but these also fail because of no database "base".
I guess I'm missing something (probably a database :-)... Thanks for some pointers or a dummy tutorial. I'm longing for something to show up in http://localhost...
I would have to guess that you are coming from a background using Access DBs. MySQL and ColdFusion do not work together by have a DB file in the CF application. CF connects to a running MySQL server somewhere on your network (even on the same machine) using a JDBC connection. It does not look at a DB file and use that. So you will need to install MySQL Server and then import the DB into that. Then use CF's datasources to connect with that.
I am a totally new on Amazon EC2 and I have just created an AMI instance (Linux).
I've installed php, apache and mysql in that instance as well and I have a question about it.
There is a .pem file which is used as a password when i connect to the instance.
If i want to connect to the instance through Visual studio, How can i get the password?
I mean, In an API function, to connect to database requires the password of the server. However, EC2 instance has .pem file as a password so how could i retrieve .pem file as a real password? (I want to make a program in VS and i need to connect to MySQL which is in the EC2 instance) well, basically, Is it possible to retrieve the password #.#????
Thanks in advance indeed!
Visual Studio Integration
One way to do it is to download the Connector/Net driver for MySQL and install it. Then in your Web.config file add a connection string similar to the below to connect to the database. Then setup your models to reflect the tables in your MySQL database. Create a DbContext class with the same name as the connection string name in your Web.config file. Then you can work with it as normal.
<connectionStrings>
<add name="SuperSmartDB" connectionString="server=ec2-50-34-34-157.compute-1.amazonaws.com;user=root;database=superrdb;port=3306;password=nunya123;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
If new to Visual Studio
Once all your models are created you can create a new controller. When creating the controller: set model class to the table you want to work with and the data context class to the context that matches your connection sting in Web.config. Select to have the CRUD create via Template. Doing so will create the basic Create, Read, Update, and Delete controller actions and views for you.
You don't need .pem file to connect to database through VS. .pem file is needed when you try to SSH into the instance. For connecting to MySQl DB, MySQL host,user and password are required.