How to Synchronize WordPress Live and Development Databases

Share this article

How to Synchronize WordPress Live and Development Databases
database synchronization

This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.

Developing WordPress themes is considerably easier with real content. Unexpected situations begin to arise when people add pages, posts, media and comments. Your beautiful template can break when:
  • editors use assets which are too big or small for your breakpoints to handle
  • managers introduce a new menu item which doesn’t fit at lower screen sizes
  • your theme implements a two-level menu hierarchy which fails to cater for the inevitable third-level page
  • long or deeply-nested comments become unreadable.
Ideally, your development server should have a snapshot of your live production server’s database. Your workflow can be improved further if content is automatically synchronized when changes occur.

Synchronization Snags

One-way WordPress database replication can be more challenging than you expect. There are good reasons why few coders live in this development dreamland…

Data Differences

WordPress stores various configuration settings in its database. This includes the domain name and paths which are used throughout posts and asset references. Importing this information into a local database (perhaps hosted at http://localhost/) will lead to undesired consequences. It may look as though it worked but image and link URLs could be taking you back to the live server. To add to the complications, WordPress serializes some data. It can be difficult to parse and change those values.

Multiple Installations

Synchronization is less necessary and complicated when you’re a sole developer working on a local installation and uploading to a single live server. Life is more complicated for teams with multiple developers, staging servers, and possibly more than on production server.

Databases can be Large

SitePoint runs on WordPress and contains many thousand articles, drafts and revisions. Even if fast incremental synchronization were implemented, you’re unlikely to want or need numerious megabytes of post data.

It’s Not Just Databases

WordPress stores uploaded images and other media in the local file system. Those need to be downloaded and the database references must be updated accordingly. You must also ensure theme and plugin files are synchronized, enabled and configured appropriately. That said, you possibly do not want certain plugins enabled, e.g. multi-site, caching, etc.

It’s Dangerous!

Could your synchronization process fail? Is it possible for synchronization to be mis-configured so development data goes live? Is there a risk the live database can be corrupted or wiped? Absolutely. Whatever solution you choose, ensure you have regular file and database back-ups from your live and development servers. Imagine losing everything. A few minutes spent running mysqldump is less troublesome than many days spent re-writing lost content!

Is Synchronization Possible?

Yes, but there’s no one-size-fits-all option. You may need two-way database synchronization. You may want one-way replication from live to development servers. Or you may want to push from development to live. You may require just pages. Or do you want posts, comments, users and other data? Is database data enough or do you want all media assets? Would you prefer to synchronize manually, at predefined intervals, or automatically? One or more of the following options may be appropriate depending on your circumstances…

WP Migrate DB Pro

Perhaps the best-known and easiest choice is the WP Migrate DB Pro WordPress plugin from Delicious Brains. The commercial product has a Media Files add-on and multi-site capabilities but a free edition is also available. Note data is pulled using in-browser Ajax methods so large databases can take time to synchronize.

WP Sync DB

WP Sync DB is an open-source fork of WP Migrate DB.

VersionPress

VersionPress is a Git-based version control plugin for WordPress which can manage database merging. The product is in development but seems promising.

WPSiteSync for Content

Offering free and commercial editions, WPSiteSync permits real-time synchronization of pages, posts and other data.

Database Sync

Database Sync is a free database-only synchronization WordPress plugin. It has not been updated for some time and is not compatible with multi-site installations but may be enough for some developers.

WordPress Importer

If you prefer a safer, more manual process, WordPress Importer exports posts, pages, comments, categories, tags, authors and other data to an XML file which can be imported into another installation. This is also a good option if you are building a live site from posts in a development system.

SyncDB

SyncDB is a bash script which synchronizes local and remote WordPress databases.

WP Staging

The WordPress WP Staging plugin is able to clone data and files from live to development or staging servers.

WordPress GitHub Sync

The WordPress GitHub Sync plugin allows you to synchronize content allows you synchronize content from a GitHub repository or Jekyll-created website. This could be an interesting option for teams requiring content editing collaboration and pull request approval workflows.

PushLive

The PushLive plugin duplicates staging to live sites with a single click. Multi-site WordPress installations are supported.

WP Stagecoach

A commercial online service which allows staging data to be merged into your live database.

MySQL Synchronization Tools

Most good MySQL database management tools offer database import, export and/or synchronization facilities. The free MySQL Workbench or is a good place to start. More advanced tools such as SymmetricDS provide features such as data transformation and filtering. Finally, you could consider options such as MySQL replication to automatically replicate data from the live master database to development slaves.

Build Your Own Solution

The only perfect solution is the one you build for your own requirements. The following tools may help:
  • mysqldump — the original MySQL schema and data back-up utility
  • mysqlpump — a new MySQL back-up utility introduced in v5.7.8 which should offer faster parallel processing and compression. Note that it is not backward-compatible with earlier versions of the database.
  • rsync — incremental file transfer
  • Git deployment options such as WP Pusher, Beanstalk and DeployBot
  • task runners such as Gulp.js or PHP alternatives such as Robo, Task and Bldr.
Do you have a perfect WordPress development and deployment workflow? Please leave your suggestions below!

For awesome WordPress hosting, we recommend SiteGround. SiteGround offers automated WordPress core and plugin updates, daily backups, and SSL certificates for free in every plan.

Frequently Asked Questions on Synchronizing WordPress Live and Development Databases

What is the Importance of Synchronizing WordPress Live and Development Databases?

Synchronizing WordPress live and development databases is crucial for several reasons. Firstly, it allows developers to test changes in a safe environment before implementing them on the live site. This reduces the risk of errors or issues affecting the live site’s functionality or user experience. Secondly, it ensures that the live and development sites are identical, making it easier to troubleshoot issues and maintain consistency. Lastly, it simplifies the process of updating the live site, as changes can be easily transferred from the development site.

How Can I Safely Synchronize My WordPress Databases?

Safely synchronizing your WordPress databases involves several steps. Firstly, always back up your live site before making any changes. This ensures that you can restore the site if anything goes wrong. Secondly, use a reliable synchronization tool or plugin, such as WP Migrate DB Pro or VersionPress. These tools automate the synchronization process and reduce the risk of errors. Lastly, test your changes thoroughly on the development site before transferring them to the live site.

What are the Best Tools for Synchronizing WordPress Databases?

There are several reliable tools for synchronizing WordPress databases. WP Migrate DB Pro is a popular choice due to its ease of use and comprehensive features. It allows you to push and pull your databases, replace URLs, and handle serialized data. VersionPress is another excellent tool, particularly for developers, as it tracks all changes and allows you to easily revert to previous versions. Other notable tools include SyncDB, WP Sync DB, and WP Staging.

Can I Synchronize My WordPress Databases Manually?

Yes, it is possible to synchronize your WordPress databases manually, although it is more complex and time-consuming than using a tool or plugin. The manual process involves exporting your database from the development site, replacing the URLs, and then importing it to the live site. However, this method requires a good understanding of databases and SQL, and there is a higher risk of errors.

What are the Risks of Not Synchronizing WordPress Databases?

Not synchronizing your WordPress databases can lead to several issues. Firstly, it can result in inconsistencies between your live and development sites, making it harder to troubleshoot issues or implement changes. Secondly, it can increase the risk of errors or issues on your live site, as changes are not tested in a safe environment before being implemented. Lastly, it can make the process of updating your live site more complex and time-consuming.

How Often Should I Synchronize My WordPress Databases?

The frequency of synchronization depends on how often you make changes to your site. If you regularly update your site or add new content, you should synchronize your databases frequently to ensure that your live and development sites are identical. However, if you only make changes occasionally, you may only need to synchronize your databases when these changes are made.

Can I Synchronize My WordPress Databases Without a Plugin?

Yes, it is possible to synchronize your WordPress databases without a plugin, although it is more complex and requires a good understanding of databases and SQL. This process involves manually exporting your database from the development site, replacing the URLs, and then importing it to the live site. However, using a plugin or tool can simplify this process and reduce the risk of errors.

What Should I Do If I Encounter Errors During Synchronization?

If you encounter errors during synchronization, the first step is to check the error message for clues about what went wrong. Common issues include incorrect database credentials, issues with serialized data, or problems with the import/export process. If you’re using a plugin or tool, check their documentation or support forums for help. If you’re synchronizing manually, you may need to consult with a developer or database expert.

Can I Use Synchronization to Move My Site to a New Server?

Yes, you can use synchronization to move your WordPress site to a new server. This process involves exporting your database from the old server, replacing the URLs, and then importing it to the new server. However, this process can be complex and requires a good understanding of databases and SQL. Using a migration plugin or tool can simplify this process and reduce the risk of errors.

How Can I Ensure That My Synchronization Process is Secure?

Ensuring that your synchronization process is secure involves several steps. Firstly, always use secure connections when transferring data between your live and development sites. Secondly, use reliable and trusted tools or plugins for synchronization. Thirdly, always back up your live site before making any changes. Lastly, regularly update your WordPress software, plugins, and themes to ensure that they are secure and up-to-date.

Craig BucklerCraig Buckler
View Author

Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.

databasejoelfmysqlsitegroundWordPressworkflow
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week