When cleaning websites that have large databases, regular text editors can’t even open the database dumps (Notepad++ supports files up to 2GB in size). So to run a search and replace on large database dumps I suggest using regex-replace line-by-line in PHP, or setting up WPCLI and running regex search & replace.
Here is a quick one-liner WP-CLI command to search & replace in WordPress database using regex.
wp search-replace 'what-to-replace' 'replace-with' --all-tables --dry-run --report-changed-only --precise --regex --regex-delimiter='/'
Here’s a breakdown of what this command does:
–all-tables | run the search & replace on all WordPress tables in the database |
–dry-run | only show what will be changed without actually changing anything |
–report-changed-only | report changed fields only |
–precise | force the use of PHP (instead of SQL) |
–regex | search using the regular-expression provided |
–regex-delimiter | set the regular-expression delimiter to ‘/’ |
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂