access MySQL of scaled OpenShift application


One of the great things about running code on OpenShift is the auto-scaling properties of cartridges. One just needs to specify during the setup (via the command line or the web interface) the level of scaling.

Getting root-ish access to the MySQL cartridge schema becomes a tad troublesome in these instances. PHPMyAdmin is not supported for scaled apps, and to keep developers from committing a security faux pas, the MySQL instance (or db of choosing) runs in a virtual network of sorts, inaccessible to the at-large Internet.

The Goods

  1. SSH into your application with the private key you added to your account. See Remote Access to Your Application for more.
  2. env | grep "mysql". Should return back an environment variable, OPENSHIFT_MYSQL_DB_URL, in the listing. Should have a value like: mysql://user:password@host-domain.rhcloud.com:42424/.
  3. Setup your SSH client to tunnel all traffic directed at port 3307 to (in this example) 42424; aka local port forwarding. For a great explanation on tunneling see: SSH Tunneling Explained.
  4. SSH to the app/start the tunnel, and use the database management UI of choosing to connect to, with the user and password from the URI string. I like HeidiSQL on Windows.

210 words. Post tags: MySQL, OpenShift, scale, and port forwarding.

Post content is written by Jason Zerbe and licensed CC BY-NC 3.0.