How to import a MySQL db to OpenShift? - mysql

I've been working on a JSP project and now I want to host in on Openshift. Everything is set up except for the database. I already added MySQL 5.5 cartridge and phpMyAdmin 4.0 and I edited the credentials in my project as shown below. But how can I upload my database data to the application?
Constants in my project

Apparently, the key was to replace the variables in the DB URL with the openshift variables.

To upload your data into your database you could use a tool to manage you tables (for example Squirrel-SQL). To connect it with your openshift-database enable the port-forwarding through your rhc console so you can access the database as it would be a local one and connect to it through squirrel. (you cannot connect direcly to the remote database from openshift - only with port-forwarding)
rhc <app-name> port-forward

Related

How to switch from MySQL to Postgre on Heroku

I want to host a django project on heroku. Locally, I developed it using MySQL database. And I have also pushed it to heroku but I get an Error message whenever I run heroku open command on command prompt. The error message is Can't connect to local MySQL server through socket. Though I'm a newbie in using databases, the way I understand the error is that heroku can't connect to local MySQL server which I'm using for local development. I don't want to connect to a remote MySQL database, instead, I want to connect to Postgre database just as heroku recommended.
Being a newbie in the use of database, I don't know the best way to migrate to Postgre or how to add MySQL in my project to .gitignore. Is it possible for me to start running Postgre on heroku while MySQL isn't added to . gitignore and is still the database in settings.py? Must I clear MySQL database or add it to gitignore before I can use Postgre?
PostgreSQL settings for Heroku:
Please install dj_database_url using below command:
pip install dj-database-url
In settings.py , import dj_database_url and add below settings at the end of the file:
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
Done !! Now, deploy again to Heroku.

I get an error EHOSTUNREACH when trying to connect 1 openshift application in NodeJS with MySQL of another openshift application

I have 2 applications on OpenShift: 1 with MySQL, and 1 with NodeJS that is going to connect to MySQL of the other app.
I've seen examples but none of them seem to work, these are the steps I'm taking:
rhc ssh -a mydbappname
then i get the enviroment variables with
env | grep MYSQL
I get something like:
OPENSHIFT_MYSQL_DB_HOST=127.XX.XXX.X
OPENSHIFT_MYSQL_DB_PORT=3306
After that i try to use those on the other app, but it always throws EHOSTUNREACH, no matter if i create the OPENSHIFT_MYSQL_DB env variables on the Node app and use them, or if i put it directly on the code.
I have seen in other parts that the OPENSHIFT_MYSQL_DB_HOST is something like 54d10be2503e36378e0002db-mydbappname.apps.rhcloud.com.
If I use the port-forward and use 127.0.0.1 with the local port selected for mysql, and start the NodeJS application locally it works, only when i upload the changes to Openshift it fails
In this article:
https://blog.openshift.com/sharing-database-across-applications/
You can read:
"Step 1: Create an application with a database
We will create a scalable PHP application using a MySQL database cartridge. In non-scalable applications, the database will be installed in the same gear as the application. In this case we want the database to be accessible from other gears. So creating a scalable application ensures that the database runs in its own gear that can be accessed from other gears."
So maybe this is the problem, check if this application you created is scalable.

Openshift : phpMyAdmin alternative for python mySql

I created a python app and add mySql as database. I can not add phpMyAdmin . Is there any other visual interface like phpMyAdmin for my python mySql database to interact with it ?
The only reason that you would not be able to add phpMyAdmin is if you are running a scaled application. Adding the phpMyAdmin cartridge is not dependent on what type of web framework cartridge you are using.
If you still can't / don't want to use phpMyAdmin, you can always use port forwarding and install something like MySQL WorkBench locally and use it.
Port forwarding: https://developers.openshift.com/en/managing-port-forwarding.html

How to push my Mysql database to heroku via mysql workbench?

I have created cleardb on heroku, I want to push my mysql database on local disk to heroku. I have mysql workbench installed. How can i push it to heroku ?
look at the output of heroku config - you will see an key called CLEARDB_DATABASE_URL this is the connection string your application uses to talk to your database.
You can take this URL and break it up into it's constituent parts to get a username, password, host, port and database name which you can use in a connection via mysql workbench.
See https://devcenter.heroku.com/articles/cleardb for further reference.
If u want to just push your database, use console, it's simple:
heroku db:push

Grails DataSource for remote MYSQL database access and migrations

Is it possible for locally running grails application to access and update remote MySQL db?
Assume the remote server is linux on which tomcat, MySQL are installed in the usual places.
Assume remote URL is accessed as tom#189.124.24.249. So grails needs to access the db as the user 'tom' or does it need to be the root user or mysql user??? Does the password of user tom need to be specified in the DataSource.groovy? In MYSQL the db test_db is configured to be accessed with user name 'guru' and password 'secret'.
If the same grails application is also running on the remote server accessing that remote db, a locally running instance of grails application accessing the same remote db should not cause any problems??
Assume the remote db name is test_db.
I need this also in context with liquibase grails plugin and database migrations. I need to run grails migrate command against the remote db to synchronize it with local db.
A side question: how do I synchronize local db in which table data is already populated to remote fresh newly created db with no data? This seems to fall under the domain of db content migrations which is not covered by the grails plugin as far as I know. I would like to know what would be the correct approach to this in the context of a grails application.
you just need to set the proper credentials in the Datasource.groovy and it all should work fine. We are running our app in a production environment and the database server is on a different box.
I dont think that two applications accessing the database server should be a problem.
Can't help with the side question... sorry
I believe, it's mostly a duplicate of Liquibase Grails database migrations
For side question: after Grails migrates structure, mysqldump or whatever backup/restore procedure should work.