Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenShift: Share MySQL-database between two applications

I have the following problem.

I have two application created app_1 and app_2

On app_1 MySQL is installed and has the following parameters:

OPENSHIFT_MYSQL_DB_PORT = 3306
OPENSHIFT_MYSQL_DB_HOST = 127.9.101.2
OPENSHIFT_MYSQL_DB_PASSWORD = xxxx
OPENSHIFT_MYSQL_DB_USERNAME = xxxx
OPENSHIFT_MYSQL_DB_SOCKET = / var/lib/openshift/5252ca504382ecccc30000ca/mysql / / socket / mysql.sock
OPENSHIFT_MYSQL_DB_URL = mysql :/ / admindWSK1aY: [email protected]: 3306 /

OPENSHIFT_MYSQL_DB_LOG_DIR = / var/lib/openshift/5252ca504382ecccc30000ca/mysql / / log /

On app_1 I can easily connect via MySQL shell on my local database.

And command looks like this.

mysql -h 127.9.101.2 -u xxx -pxxx db325771

But when I run the same command on app_2, I get the following error message.

ERROR 2003 (HY000): Can not connect to MySQL server on '127 .9.101.2 '(113)

What am I doing wrong? How can I share one DB for a two apps?

Thank you

like image 262
user1167253 Avatar asked Jan 26 '26 03:01

user1167253


2 Answers

1) You need to create app 1 as a scalable database (rhc app create myapp pyton-2.6 mysql-5 -s)

2) You need to use the URL (not the ip) for the database in app_2

That should do it for your use case

like image 65
TheSteve0 Avatar answered Jan 28 '26 18:01

TheSteve0


The way to do this is as follows:

  1. Make a scalable application with mysql. OpenShift does not currently expose the ports for mysql to the internet except for scalable appications.
  2. In the second app, you must use the DNS of the application with mysql and the value of the OPENSHIFT_MYSQL_DB_PROXY_PORT environment variable from that application when connecting to the mysql instance in the first application.
like image 39
Paul Morie Avatar answered Jan 28 '26 17:01

Paul Morie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!