0

i need Mysql IP for custom wordpress installation as it not support "localhost" mysql host address.In rhc window client i use port forward command rhc port-forward -a appname but it show openshift IP address of HAPROXY and httpd not for Mysql.how to find openshift MYSQL IP.link for port-forward rhc command result iamge

Example Command Line screenshot

timo.rieber
  • 3,727
  • 3
  • 32
  • 47
gill
  • 83
  • 1
  • 9

3 Answers3

3

You can print the MySQL <ip>:<port> using the following command:

rhc ssh <app> 'echo $OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT'

However, it's recommended to use OpenShift's environment variables instead of hard-coded numbers, as they are generic and thus you don't need change anything while migrating the app from gear to gear:

/* Environment variables exposed by MySQL database cartridge */
define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST')); // 127.0.250.1
define('DB_PORT', getenv('OPENSHIFT_MYSQL_DB_PORT')); // 3306
define('DB_USER', getenv('OPENSHIFT_MYSQL_DB_USERNAME')); // admin
define('DB_PASS', getenv('OPENSHIFT_MYSQL_DB_PASSWORD')); // 8ddTnst22X3Y
define('DB_NAME', getenv('OPENSHIFT_APP_NAME')); // myapp
define('DB_SOCKET', getenv('OPENSHIFT_MYSQL_DB_SOCKET')); // $OPENSHIFT_MYSQL_DIR/socket/mysql.sock
define('DB_STRING', getenv('OPENSHIFT_MYSQL_DB_URL')); // mysql://admin:8ddTnst22X3Y@127.0.250.1:3306/
Vojtech Vitek - golang.cz
  • 25,275
  • 4
  • 34
  • 40
  • vojtech vitek, i use rhc ssh 'echo $OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT' command too.but it give me same result 52eee....-upme.rhcloud.com:37501. is there is kind of order exist in which IP is assign to cartidge ?.if yes,then IP of MYSQL will be find as IP address of HAPROXY and httpd is known – gill Feb 07 '14 at 13:30
1

You can ssh into your app and run env | grep MYSQL

niharvey
  • 2,807
  • 2
  • 15
  • 24
  • how i ssh into app i already upload public key to openshift account – gill Feb 03 '14 at 03:47
  • 1
    From the directory of your application run `rhc ssh -a ` – niharvey Feb 03 '14 at 03:50
  • after ssh into app how i type env | grep MYSQL my keyboard have no button like | morever paste function not work in cmd after ssh into app – gill Feb 03 '14 at 04:12
  • after typing mysql command for ssh into app. It Opens an interactive MySQL shell. what command will be use to find mysql openshift IP? – gill Feb 03 '14 at 04:26
  • after env|grep MYSQL command result still not show IP address:( http://imgur.com/pecVtIk – gill Feb 03 '14 at 13:26
  • You should checkout https://github.com/openshift/wordpress-example/blob/master/php/wp-config.php for an example of how wordpress is configured to work on Openshift – niharvey Feb 03 '14 at 14:41
  • `rhc ssh -a gives me "No system SSH available. Please use the --ssh option to specify the path to your SSH executable, or install SSH.", but I can deploy my app with SSH. – alayli Feb 13 '14 at 15:49
0

SSH into your app using command rhc ssh <app> after ssh into your app, type in env | grep MYSQL then find OPENSHIFT_MYSQL_DB_HOST and copy the value it has something like this OPENSHIFT_MYSQL_DB_HOST = 56********************43-<domain>.rhcloud.com you need the second part, which is 56********************43-<domain>.rhcloud.com then while you are still inside the shell (ssh) of your app, ping the address you just got, ping 56********************43-<domain>.rhcloud.com . the resulting IP is the MYSQL server IP. I usually use the port in OPENSHIFT_MYSQL_DB_URL attached to the ip.

This may (not sure) differ in different apps.

You can extract the value of OPENSHIFT_MYSQL_DB_URL from the env | grep MYSQL command I described above.

The value is something similar to this OPENSHIFT_MYSQL_DB_URL=mysql://<MySQLusername>:<MySQLpassword>@56********************43-<domain>.rhcloud.com:61836

You could extract all the required info from here too.

Good luck on using it!

Hossein
  • 525
  • 3
  • 13