Make a dump of your MySQL DB on OpenShift

If you want to make a backup of your database or just want to create a dump to migrate your db to another provider, you need to do these steps:

1. Connect to your running application trough SSH. To do that you need to click this link on OpenShift and run the displayed command.

Screen Shot 2016-05-16 at 11.56.00 AM

2. Create the dump using this command:

mysqldump -u $OPENSHIFT_MYSQL_DB_USERNAME -h $OPENSHIFT_MYSQL_DB_HOST --password=$OPENSHIFT_MYSQL_DB_PASSWORD $OPENSHIFT_GEAR_NAME > dump.sql
gzip dump.sql

3. After that you can scp the dump to any location you want.

WordPress configuration for OpenShift

If you are trying to upload a WordPress site to OpenShift you will have to make the following adjustments to your wp-config.php file:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME',$_ENV['OPENSHIFT_GEAR_NAME']);

/** MySQL database username */
define(‘DB_USER’, $_ENV[‘OPENSHIFT_MYSQL_DB_USERNAME’]);

/** MySQL database password */
define(‘DB_PASSWORD’, $_ENV[‘OPENSHIFT_MYSQL_DB_PASSWORD’]);


/** MySQL hostname */
define('DB_HOST', $_ENV['OPENSHIFT_MYSQL_DB_HOST'] . ':' . $_ENV['OPENSHIFT_MYSQL_DB_PORT']);

This will help WordPress to use the environment variables that OpenShift setup to connect to MySQL.