Skip to content

Instantly share code, notes, and snippets.

@rdela
Forked from harryfinn/wp-cli-migrate-db.md
Created September 25, 2023 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdela/35d981a3613db329353930732b585a98 to your computer and use it in GitHub Desktop.
Save rdela/35d981a3613db329353930732b585a98 to your computer and use it in GitHub Desktop.
WP-CLI DB migrate instructions

Instructions for using WP-CLI to migrate a WordPress DB

# Export current (local) DB
wp db export db.sql

# Copy file from local to server (may need to amend server path if not in html folder)
# The example below is for local to remote, simply swap these 2 around for remote to local
scp -r db.sql www-data@IP_ADDRESS:/var/www/html

# SSH onto box (should be same connection details as above)
ssh www-data@IP_ADDRESS

# Run the WP CLI DB importer
wp db import db.sql

# Use --dry-run first to check that changes will be OK in DB
wp search-replace old-site-url.co.uk new-site-url.co.uk --dry-run
wp search-replace old-site-url.co.uk new-site-url.co.uk

# Delete imported DB file
rm db.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment