These are the steps I follow when I move (a.k.a. migrate) the database for a website to my local computer using WP CLI.
Backup Local Database
wp db export local-retire.sql
Pull Remote Database Locally
wp @prod db export - > prod.sql
Replace Local Database with Remote
wp db import prod.sql
Change URL to development URL
wp search-replace 'https://example.com' 'https://example.dev' --skip-columns=guid --dry-run
Note: If you’re dealing with multisite you might need to add --url=https://example.com
Update Multisite Tables
This is only necessary when working with multisite
wp search-replace 'example.com' 'example.dev' wp_site wp_blogs --dry-run
Create a new admin/password user
wp user create admin admin@example.com --role=administrator --user_pass=password
Leave a Reply