Cloning the Database
Making a copy of your public database and getting it up and running on your local website is extremely easy and straightforward - providing that the table prefix on both systems is the same.
The method I use which is both quick, easy and straightforward is via the excellent phpMyAdmin plugin for WordPress and involves just a few easy steps. if you don’t have this plugin, download it and install it - it is an invaluable tool.
- Open the phpMyAdmin plugin page in your public sites admin pages.
- Select the ‘Export’ option from the list near the top.
- When the export screen displays, click on ‘Select All’ underneath the list of tables and ensure the ‘SQL’ option is set.
- Ensure both the ‘Structure’ check box is checked and also check the option ‘Add DROP TABLE’
- Ensure that the ‘Data’ checkbox is checked.
- Check the ‘Save as File’ box, select your preferred compression and click on ‘Go’.
The resultant file contains all of the data of your public site along with the table definitions required to recreate the database.
Next, unzip the file and load it up in your plain text editor. Once again TextWrangler is an ideal tool for this task.
All you are going to do with this file is a global find and replace. Using my own site as an example once again I search on:
www.yellowswordfish.com
and replace all with:
www.yellowswordfish.dev
and save the file. Once saved it is also worth zipping it as some versions of phpMyAdmin only work with a compressed file.
- Now open your local site in admin mode and navigate to the local copy of the phpMyAdmin plugin.
- Select ‘Import’ from the row of options near the top.
- Supply the location of your edited and zipped database file.
- Click on ‘Go’.
Once again, if all has gone without hitch, when you reopen your local site you will have a carbon copy of your public site.
And don’t forget, you can repeat this procedure whenever you want to keep your local system up to daye with your public site.