0

I have a wp db dump file inside my site directory. Can someone show me an example of how to use wp-cli search and replace command on the static sql file, not the active db to change my url from "old-example.com" to "new-example.com"

/var/www/html/wp-site.com/dumps/oldexample.com/dumpeddb.sql

/var/www/html/wp-site.com/dumps/newexample.com/ready-for-import.sql

Not quite sure how to apply this to already exported db dump.
$wp search-replace foo bar --export=database.sql

4
  • 1
    wp search-replace will only work to the current database which is configured in wp-config.php
    – Den Isahac
    Oct 21 at 22:40
  • you would need to import it into a database first, you can't run an SQL query on an SQL file it has to be ran first
    – Tom J Nowell
    Oct 21 at 23:18
  • OK.. I was afraid of that... was trying to avoid it... always feel better know the db is healthy before importing it. might there be a sed solution?
    – mjones
    Oct 22 at 0:17
  • I found a one line solution here: stackoverflow.com/questions/11839060/… "sed -i 's/oldString/newString/g' ./db.sql"
    – mjones
    Oct 22 at 0:35
1

This is not possible, WP CLI uses SQL queries to acquire and update information. You would need to import the SQL file into a database to perform a search replace with WP CLI.

3
  • OK.. I was afraid of that... was trying to avoid it... always feel better know the db is healthy before importing it. might there be a sed solution?
    – mjones
    Oct 22 at 0:17
  • I found a one line solution here: stackoverflow.com/questions/11839060/… "sed -i 's/oldString/newString/g' ./db.sql"
    – mjones
    Oct 22 at 0:35
  • that only works because it has the same number of characters, WP CLI search replace does more than just a direct substitution. An SQL file is not a database with a health that can be queried, it's just a text file of INSERT queries
    – Tom J Nowell
    Oct 22 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.