Database migration WordPress

The ultimate guide to stress-free WordPress database migration

Why Database Migration WordPress Matters for Your Business

Database migration WordPress is the process of moving your WordPress site’s database from one location to another while preserving all your content, settings, and user data. Here’s what you need to know:

Quick Answer: Essential Steps for WordPress Database Migration

  1. Back up everything – Create complete copies of your database and files before starting
  2. Export your database – Use phpMyAdmin or WP-CLI to create an SQL file
  3. Create new database – Set up a fresh database on your destination server
  4. Update wp-config.php – Change database credentials (DBNAME, DBUSER, DBPASSWORD, DBHOST)
  5. Import the database – Upload your SQL file to the new location
  6. Update URLs – Search and replace old domain references if changing domains
  7. Test thoroughly – Verify all content, functionality, and links work correctly

Whether you’re switching hosting providers, moving to a staging environment, or upgrading your server infrastructure, database migration is a critical skill for maintaining your WordPress site. The process can seem daunting, especially when you consider that your database contains everything from your blog posts and pages to user accounts and plugin settings.

Research shows that over 60 million websites worldwide rely on migration tools, and popular plugins like WP Migrate have over 300,000 active installations. Yet many site owners struggle with common issues like corrupted serialized data, broken URLs, and connection errors that can take your site offline if not handled properly.

I’m Kevin Gallagher, and over my fifteen years running a web design company and founding wpONcall, I’ve handled database migration WordPress tasks for hundreds of sites ranging from small business blogs to complex enterprise installations. Through building over 2,500 WordPress websites and managing countless migrations, I’ve learned exactly what works and what pitfalls to avoid.

Simple Database migration WordPress word guide:

Understanding Database Migration WordPress Essentials

To master the art of moving a website, we must first understand what lives inside the engine room. In WordPress, the database is the brain. While your files (themes, plugins, and images) provide the body and clothing, the database stores every piece of information that makes your site unique. Without a properly functioning database, your WordPress installation is simply a collection of empty folders and static code.

WordPress primarily uses MySQL or MariaDB to store its data. These are relational database management systems that organize data into tables. When we talk about Database migration WordPress, we are referring to the structured movement of these data tables from one server environment to another. This process requires precision because the database doesn’t just store text; it stores relationships between different types of data. For instance, a post ID in one table must correctly map to the category ID in another, or your site’s navigation and organization will collapse.

What is Inside the Database?

A standard WordPress database consists of several core tables. Understanding these is vital for ensuring data integrity during a migration. For a comprehensive overview of how to manage these assets, you can refer to the official WordPress documentation on backing up your database.

  • wp_posts: This is the heart of your content. It stores every post, page, and even the metadata for your media library items. It also stores custom post types, which are essential for modern WordPress themes and plugins.
  • wp_postmeta: This table stores additional information about your posts, such as SEO settings, custom fields, and page builder data. It is often the largest table in the database.
  • wp_options: This table contains all the site-wide settings, including your site URL, blog name, and active plugin configurations. It is often the most critical table to update during a migration because it dictates where the site thinks it is located.
  • wpusers and wpusermeta: These store your user accounts, encrypted passwords, profile information, and user-specific settings like dashboard preferences.
  • wpcomments and wpcommentmeta: All the engagement from your readers lives here, including approved comments, spam, and metadata like the commenter’s IP address.
  • wpterms, wptermtaxonomy, and wpterm_relationships: These three tables work together to handle your categories, tags, and custom taxonomies. They are highly relational and must be migrated carefully to avoid breaking your site’s structure.

For more details on how to protect these assets, you can explore our resources on WordPress backup and migration.

Portability and Environments

Migrations often occur between different server environments. You might be moving from a local development setup (like LocalWP or WAMP) to a staging environment for testing, or finally pushing that staging site to production (live). Each move requires a precise transfer of the data structure to ensure nothing is lost in translation.

In a professional workflow, we often use “Environment Parity,” which means the local, staging, and production servers are configured as identically as possible. This reduces the risk of the database behaving differently after a migration due to variations in MySQL versions or PHP configurations. When migrating, you must also consider the “Collation” of the database—this is the set of rules that the database uses to compare and sort characters. If the source and destination have different collations (e.g., utf8mb4_unicode_ci vs utf8mb4_general_ci), you may encounter errors during the import process.

Why Database Migration WordPress is Necessary

In our experience at wpOncall, we see several common scenarios that trigger the need for a migration. It isn’t just about moving to a new host; it is about keeping your digital infrastructure modernized and agile.

  1. Performance Scaling: As your business grows, your initial shared hosting may no longer cut it. Moving to a VPS or dedicated server requires a database migration to take advantage of better hardware. High-traffic sites often require database optimization during the migration to ensure the new server can handle the load.
  2. Domain Changes and Rebranding: If you are switching from oldbrand.com to newbrand.com, your database must be migrated and updated to reflect the new identity. This involves a complex search-and-replace operation that goes beyond simple text changes.
  3. Environment Synchronization: Developers need to “pull” the latest live data to a local environment to debug issues without risking the live site. This ensures that the developer is working with the exact same data that the users are seeing.
  4. Disaster Recovery: If a server fails, having a portable database allows us to restore your business on a completely different infrastructure in minutes. A robust migration strategy is the backbone of any disaster recovery plan.
  5. Site Cloning: Sometimes you need to create an exact replica of a successful site to launch a second branch or a niche-specific version of your service. Cloning requires a full database migration followed by specific configuration changes to differentiate the new site.

Step-by-Step Manual Database Migration WordPress Process

While many prefer the ease of plugins, understanding the manual process is the mark of a true WordPress expert. Manual migration gives you total control and is often necessary for extremely large databases that cause plugins to time out. For those working with large-scale data, the MySQL documentation on mysqldump provides essential technical details on how to export data via the command line.

The Manual Workflow

Feature Manual Migration (phpMyAdmin/WP-CLI) Plugin-Based Migration
Control Absolute control over every table Limited to plugin settings
Speed Faster for massive databases (>1GB) Faster for small to medium sites
Difficulty High – requires technical knowledge Low – user-friendly interfaces
Risk High if SQL is edited incorrectly Low due to automated safeguards

1. Exporting the Source

The most common tool for this is phpMyAdmin. You select your database, click the “Export” tab, and choose the “Quick” method with the SQL format. For power users, using WP-CLI (WordPress Command Line Interface) with the command wp db export is significantly faster and more reliable for databases that exceed several hundred megabytes. This method avoids the execution time limits often imposed by web browsers and web servers.

2. Preparing the Destination

On your new server, you must create a fresh, empty database. Take note of the four essential credentials:

  • DB_NAME: The name of the new database.
  • DB_USER: The user assigned to the database.
  • DB_PASSWORD: The secure password for that user.
  • DB_HOST: Usually ‘localhost’, but sometimes a specific IP or hostname provided by your host.

3. Updating wp-config.php

The wp-config.php file is the bridge between your files and your database. You must edit this file on the new server to include the credentials you just created. Ensure the table prefixes (e.g., wp_) match the source database. If your source used a custom prefix like wp_custom_, and your new installation uses the default wp_, the site will prompt you for a fresh installation because it cannot find the expected tables.

4. Importing the SQL File

Back in phpMyAdmin on the new server, select your empty database and click “Import.” Upload the SQL file you exported earlier. If you have SSH access, the command wp db import filename.sql is the most reliable way to handle this, as it bypasses PHP’s upload_max_filesize and post_max_size limits.

Pre-Migration Checklist and Best Practices

Migration Checklist - Database migration WordPress

A successful Database migration WordPress starts long before you click “Export.” Preparation is the difference between a five-minute transition and a five-hour headache. We recommend the following best practices to ensure a seamless move:

  • Full Backups: Never start without a fresh backup of both the database and the wp-content folder. This is your safety net. If the migration fails, you can always revert to the original state.
  • Plugin Deactivation: Deactivate heavy security and caching plugins before exporting. These often store server-specific paths or firewall rules that can cause conflicts on a new host. Caching plugins, in particular, can serve “ghost” versions of your site that make it difficult to verify if the migration was successful.
  • Check Server Requirements: Ensure the destination server uses a compatible PHP version (ideally 8.1 or higher) and the same database type (MySQL vs. MariaDB). You should also check the max_allowed_packet setting in your MySQL configuration; if this is too low, large database rows (like those containing long page builder content) will fail to import.
  • Database User Privileges: Ensure the new database user has “ALL PRIVILEGES” assigned. Without this, WordPress won’t be able to write new posts, update options, or even create temporary tables required by some plugins.
  • Optimize Before You Move: Run a “Repair” and “Optimize” command in phpMyAdmin to clear out overhead and transients. Transients are temporary data stored in the wp_options table that can often be safely deleted, significantly reducing the SQL file size.
  • Maintenance Mode: Put your live site in maintenance mode during the export. This prevents users from placing orders or leaving comments that would be lost because they occurred after the export was generated.
  • DNS TTL Adjustment: If you are changing servers, lower your DNS Time-To-Live (TTL) to 300 seconds (5 minutes) at least 24 hours before the move. This ensures that when you update your IP address, the change propagates across the internet almost instantly.
  • Verify Character Sets: Ensure both servers are using the same character set, typically utf8mb4. Mismatched character sets can lead to “mojibake”—where special characters like emojis or accented letters turn into unreadable symbols like é.

For a deeper dive into the technical requirements for the coming years, check out our WordPress Migration Guide 2025.

Handling Serialized Data and URL Updates

This is where most DIY migrations go wrong. WordPress doesn’t just store simple strings; it uses serialized arrays and objects to store complex data structures in a single database cell. This is common for theme settings, widget configurations, and plugin data.

The Danger of “Search and Replace”

If you open a SQL file in a text editor and do a standard “find and replace” to change a URL, you will likely break the site. Serialized data includes a character count as part of its structure. For example, a widget might store a URL like this: s:19:"http://oldsite.com";. The s:19 indicates that the following string is 19 characters long. If you change it to http://newsite.com (18 characters) without updating the s:19 to s:18, the PHP unserialize() function will fail because the expected length does not match the actual length. This results in the data becoming “corrupted,” and your widgets or theme settings will simply disappear from the front end.

To understand the underlying logic of how PHP handles this data, you can consult the PHP manual on serialization. Understanding this concept is crucial for anyone performing a manual Database migration WordPress.

How to Do It Properly

To maintain database integrity, we use tools that “unserialize” the data, perform the replacement, and then “re-serialize” it with the correct counts.

  • WP-CLI: The command wp search-replace 'olddomain.com' 'newdomain.com' is the gold standard. It is fast, handles serialization perfectly, and can be run with a --dry-run flag to see how many replacements will be made before actually committing them to the database.
  • Plugins: Specialized tools like WP Migrate or All-in-One WP Migration handle this automatically during the export or import process. They are excellent for users who are not comfortable with the command line.
  • Scripts: For those without CLI access, the Search and Replace DB script by interconnect/it is a powerful PHP-based utility. However, it must be deleted immediately after use, as it poses a significant security risk if left on a public server.

Absolute vs. Relative URLs

WordPress generally stores absolute URLs (e.g., https://example.com/image.jpg) rather than relative paths (e.g., /image.jpg). These are found in the wp_posts content and the wp_options table. The GUID fields in the wp_posts table are a special case; they should generally be left alone for existing posts to avoid issues with RSS readers, which use the GUID to determine if a post is new. However, almost every other instance of the old URL needs a thorough update to ensure the site functions correctly on the new domain. For more pro tips, see our guide on how to Migrate your site like a pro.

Troubleshooting Common Migration Errors

WordPress Errors - Database migration WordPress

Even with the best planning, errors can occur during a Database migration WordPress. Here is how we fix the most common issues that arise:

1. Error Establishing a Database Connection

This is the most frequent error and usually means your wp-config.php credentials do not match the database you created on the new server.

  • Check DB_HOST: Some hosts require an IP address or a specific socket path (like :/tmp/mysql5.sock) instead of “localhost.”
  • Check User Permissions: Ensure the user is actually added to the database with all privileges. In many control panels, creating the user and creating the database are two separate steps, and you must manually link them.
  • Test Connection: You can create a small PHP script called test.php with a simple mysqli_connect call to verify if the credentials work outside of WordPress.

2. 500 Internal Server Error

This is a generic error that often points to a problem with the .htaccess file or PHP memory limits.

  • .htaccess: After a migration, the file paths in .htaccess might still point to the old server’s directory structure. This is especially common if you moved from a subdirectory to the root or vice versa. For more information on how this file works, see the Apache .htaccess guide.
  • PHP Memory: If the new server has a lower memory_limit than the old one, the site may crash. Increase this in your wp-config.php using define('WP_MEMORY_LIMIT', '256M');.

3. White Screen of Death (WSoD)

This is typically a PHP error that is being hidden from the user. To diagnose it, enable WordPress debug mode in wp-config.php by setting define('WP_DEBUG', true);. This will display the specific error on the screen. Often, it is a plugin that is incompatible with the new server’s PHP version or a missing PHP extension (like php-xml or php-gd) that the theme requires.

This happens when the URL update step was missed or incomplete. If images are appearing as broken icons, check the wp_posts table to see if the URLs still point to the old domain. Also, ensure that the physical files were moved to the correct wp-content/uploads directory and that the folder permissions are set to 755 so the web server can read them.

5. Database Collation Mismatch

If you see strange characters or the import fails with an error like Unknown collation: 'utf8mb4_unicode_520_ci', it means your new server’s MySQL version is older than the source. You may need to export the database using a “Compatibility” mode or manually search and replace the collation string in the SQL file before importing.

Post-Migration Testing and Verification

Once the database is imported and the URLs are updated, our work isn’t done. A migration is only successful once it has been verified through a rigorous testing protocol. At wpOncall, we follow these steps for every Database migration WordPress:

  1. Permalink Refresh: This is the most important post-migration step. Navigate to Settings > Permalinks and click “Save Changes” twice. This flushes the rewrite rules in the database and regenerates the .htaccess file, ensuring that your internal links don’t lead to 404 errors.
  2. Media Library Check: Scroll through your media library in the dashboard. If thumbnails are missing, it usually indicates a path error in the database or that the files were not fully uploaded. Use a plugin like “Regenerate Thumbnails” if the files exist but the database references are broken.
  3. Form Testing: Submit a test entry on every contact form. Migrations can sometimes break the connection to the mail server (SMTP) or the database table where entries are stored. Ensure that the notification emails are being sent and received correctly.
  4. SSL Verification: Ensure that the site loads over HTTPS and that there are no “mixed content” warnings. Mixed content occurs when the database still contains http:// links for images or scripts while the site is running on https://. You can use a “Search and Replace” tool to fix these globally.
  5. User Logins: Test logging in with different user roles (Admin, Editor, Subscriber). This ensures the wp_users and wp_usermeta tables migrated correctly and that user permissions (capabilities) are intact.
  6. Cache Clearing: Clear all server-side caches, including Object Cache (Redis/Memcached) and Varnish. If you use a CDN like Cloudflare, purge the entire cache to ensure users are seeing the version of the site from the new server.
  7. Check for Hardcoded Paths: Some themes and plugins hardcode server paths (e.g., /home/user/public_html/...) into the database. These must be updated to match the new server’s file structure, which you can find by looking at the __FILE__ constant in PHP or checking with your host.

Frequently Asked Questions about WordPress Databases

How do I migrate a WordPress multisite database?

Multisite migrations are significantly more complex because they involve a shared network of tables. You must handle the wp_blogs, wp_site, and wp_sitemeta tables with extreme care. Domain mapping settings often need manual updates in the database to reflect the new network structure. If you are moving a single site out of a multisite network, you will need to extract specific table IDs (e.g., wp_2_posts, wp_2_options) and rename them to the standard wp_posts format. This requires a deep understanding of the multisite database schema.

What is the best way to handle large SQL files?

Most web hosts have a 2MB to 50MB upload limit in phpMyAdmin, which is insufficient for many business sites. For databases larger than this:

  • Gzip Compression: Exporting as a .sql.gz file can reduce the file size by up to 90%, often bringing it under the upload limit.
  • BigDump: This is a free PHP script that imports large SQL files in small chunks to avoid server timeouts. It is a lifesaver when you don’t have SSH access.
  • SSH/Command Line: This is the most professional method. Upload the SQL file via SFTP and run mysql -u username -p database_name < file.sql. This method is nearly instantaneous and is not subject to PHP timeouts.

How do I update URLs after a domain change?

The most reliable way is using a "Search and Replace" tool that handles serialized data. You must update the siteurl and home rows in wp_options, all instances of the old URL in wp_posts, and any hardcoded paths in wp_postmeta. Don't forget to update the protocol if you are also moving from HTTP to HTTPS. Using WP-CLI's search-replace command is the recommended approach for developers.

Can I migrate just the database without the files?

Yes, this is common when you have already moved the files via SFTP or if you are only trying to sync content between a staging and production site. However, you must ensure that the versions of the plugins and themes on the destination server match the versions that the database expects. If the database expects a plugin to have a certain table structure that doesn't exist in the files, you will encounter errors.

Is it safe to manually edit a SQL file in a text editor?

It is generally discouraged unless you are only changing non-serialized data. If you must edit a SQL file, use a high-quality code editor like VS Code or Sublime Text that can handle large files without crashing. Never use a word processor like Microsoft Word, as it will add hidden formatting characters that will corrupt the SQL syntax and make the file impossible to import.

Conclusion

Database migration WordPress is a foundational task that ensures your website remains portable, scalable, and secure. While the manual process involves technical hurdles like handling serialized data and updating server credentials, it provides the most robust results for complex sites.

At wpOncall, we understand that your database is your most valuable business asset. We specialize in WordPress website security and support, offering the expertise needed to handle these transitions without data loss or downtime. From daily updates and backups to unlimited support, our team ensures your site is protected and improved every day.

If you are planning a move and want the peace of mind that comes with professional handling, our WordPress Site Migration service is designed to take the stress off your plate. Whether you are in Santa Rosa, CA, or operating globally, we are here to ensure your WordPress journey is smooth and successful.