How to back up your MySQL database

From SWCP Support Wiki
Revision as of 18:29, 2 May 2014 by Toddj (talk | contribs)
Jump to navigationJump to search

There are many ways to back up your MySQL database. We'll cover the simplest one, using phpMyAdmin. Of course parts of this apply specifically to a database at SWCP, but most of it would be applicable for any MySQL database accessed with phpMyAdmin.

Start by logging in to phpMyAdmin. If you don't know the servername, username or password - and your web application is using the database - you can usually find the info in the configuration files of the web application. For example, if you are using Wordpress, look in the wp-config.php file for your Wordpress directory. If you are using Joomla, they will be found in the configuration.php file in the root of your Joomla directory.

Here are the bits you'd look for in a Wordpress 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', '1234321_wp');
/** MySQL database username */
define('DB_USER', 'LongUsernamesAreStrongUsernames');
/** MySQL database password */
define('DB_PASSWORD', 'F{BvstdRvsB2oV|2XN)2qNO');
/** MySQL hostname */
define('DB_HOST', '1234321_wp.sqldb.swcp.com');

In this case, you would open http://1234321_wp.sqldb.swcp.com in your web browser, and use the LongUsernamesAreStrongUsernames/F{BvstdRvsB2oV|2XN)2qNO username/password to log in.

On the main phpMyAdmin page, you should see your database name in the upper left (right below the "Home", "Exit", etc. icons). Click it. Now there is a row of options accross the top and one of them is "Export". Click the "Export" button.

There are many options on the Export page, but most of them will already be set to good defaults. Here are a couple to check and/or change:

  • Under "Export" on the left you can pick the format of exported data. Select "SQL". You may have reason to want another format such as CSV, but in general, if the purpose is to be able to restore the database after a mishap, select SQL.
  • Click the "Save As File" option near the bottom. The File Name Template setting should already say "_DB_". If it says something else, go back to the beginning: click the database name link in the upper left, then the Export button in the upper right.
  • If your database is very large, you can select a compression option such as "Zip" under the "Save As File" option. Most databases aren't large enough for this to matter though.

Now click the "Go" button in the lower right. After a few seconds you should be prompted to save a file, which will be the backup copy of your database. You can view the backup in any text editor -- it should contain a bunch of readable SQL commands.

If you have any questions, please email help@swcp.com

See Also