admin管理员组

文章数量:1287524

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" to "new-example"

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

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

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

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" to "new-example"

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

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

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

Share Improve this question asked Oct 21, 2021 at 22:21 mjonesmjones 1531 silver badge11 bronze badges 4
  • 1 wp search-replace will only work to the current database which is configured in wp-config.php – Den Isahac Commented Oct 21, 2021 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 Commented Oct 21, 2021 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 Commented Oct 22, 2021 at 0:17
  • I found a one line solution here: stackoverflow/questions/11839060/… "sed -i 's/oldString/newString/g' ./db.sql" – mjones Commented Oct 22, 2021 at 0:35
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: customizationApplying WPcli Search amp Replace to Static SQL Dump File