Skip to content

channeladam/wordpress-sql-search-replace

Repository files navigation

WordPress SQL Search and Replace

Overview

This program will take a SQL file (exported from myPhpAdmin) and replace all occurrences of a given old value with a new value. It correctly handles replacements both within and outside of PHP Serialization data (as is used in the wp_options table).

It is useful to help with:

  • migrating a WordPress site from one subdomain URL / folder path to another
  • migrating a WordPress site from one database table prefix to another

License

Before accessing the content in this repository, please review the license with restrictions for commercial usage.

Usage

uv run wordpress-sql-search-replace <input_sql_file_path> <old_value> <new_value> <output_sql_file_path>

Examples

  • uv run wordpress-sql-search-replace path/to/sql_export.sql oldvalue newvalue path/to/output.sql

Replace a domain name, a database table prefix, and then a path segment:

  • uv run wordpress-sql-search-replace ./tests/data/all-data-to-migrate.sql test.mydomain.com.au staging.mydomain.com.au ./tests/data/all-data-to-import-temp1.sql
  • uv run wordpress-sql-search-replace ./tests/data/all-data-to-import-temp1.sql /test/ /staging/ ./tests/data/all-data-to-import-temp2.sql
  • uv run wordpress-sql-search-replace ./tests/data/all-data-to-import-temp2.sql wp_ AB9CD8EF_ ./tests/data/all-data-to-import.sql

Testing

Manual Testing:

  • uv run wordpress-sql-search-replace ./tests/data/input-simple.sql test.mydomain.com.au staging.mydomain.com.au ./tests/data/output-simple.sql

  • uv run wordpress-sql-search-replace ./tests/data/input-nested.sql test.mydomain.com.au staging.mydomain.com.au ./tests/data/output-nested.sql

  • uv run wordpress-sql-search-replace ./tests/data/input-nested-2.sql test.mydomain.com.au staging.mydomain.com.au ./tests/data/output-nested-2.sql

  • Those same manual tests are also automated with PyTest -> ./run-tests.sh

About

WordPress SQL Search and Replace

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published