search replace command
2.1.7
搜尋/取代資料庫中的字串。
快速連結:使用 |安裝 |貢獻 |支援
wp search-replace <old> <new> [<table>...] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=<file>]] [--export_insert_size=<rows>] [--skip-tables=<tables>] [--skip-columns=<columns>] [--include-columns=<columns>] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--regex-limit=<regex-limit>] [--format=<format>] [--report] [--report-changed-only] [--log[=<file>]] [--before_context=<num>] [--after_context=<num>]
搜尋選定表中的所有行,並用第二個字串取代第一個字串的出現。
預設情況下,該命令使用註冊到$wpdb
物件的表。在多站點上,除非指定--network
,否則這只是目前站點的表。
搜尋/取代智慧處理 PHP 序列化數據,且不更改主鍵值。
選項
<old> A string to search for within the database. <new> Replace instances of the first string with this new string. [<table>...] List of database tables to restrict the replacement to. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`. [--dry-run] Run the entire search/replace operation and show report, but don't save changes to the database. [--network] Search/replace through all the tables registered to $wpdb in a multisite install. [--all-tables-with-prefix] Enable replacement on any tables that match the table prefix even if not registered on $wpdb. [--all-tables] Enable replacement on ALL tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --network and --all-tables-with-prefix. [--export[=<file>]] Write transformed data as SQL file instead of saving replacements to the database. If <file> is not supplied, will output to STDOUT. [--export_insert_size=<rows>] Define number of rows in single INSERT statement when doing SQL export. You might want to change this depending on your database configuration (e.g. if you need to do fewer queries). Default: 50 [--skip-tables=<tables>] Do not perform the replacement on specific tables. Use commas to specify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`. [--skip-columns=<columns>] Do not perform the replacement on specific columns. Use commas to specify multiple columns. [--include-columns=<columns>] Perform the replacement on specific columns. Use commas to specify multiple columns. [--precise] Force the use of PHP (instead of SQL) which is more thorough, but slower. [--recurse-objects] Enable recursing into objects to replace strings. Defaults to true; pass --no-recurse-objects to disable. [--verbose] Prints rows to the console as they're updated. [--regex] Runs the search using a regular expression (without delimiters). Warning: search-replace will take about 15-20x longer when using --regex. [--regex-flags=<regex-flags>] Pass PCRE modifiers to regex search-replace (e.g. 'i' for case-insensitivity). [--regex-delimiter=<regex-delimiter>] The delimiter to use for the regex. It must be escaped if it appears in the search string. The default value is the result of `chr(1)`. [--regex-limit=<regex-limit>] The maximum possible replacements for the regex per row (or per unserialized data bit per row). Defaults to -1 (no limit). [--format=<format>] Render output in a particular format. --- default: table options: - table - count --- [--report] Produce report. Defaults to true. [--report-changed-only] Report changed fields only. Defaults to false, unless logging, when it defaults to true. [--log[=<file>]] Log the items changed. If <file> is not supplied or is "-", will output to STDOUT. Warning: causes a significant slow down, similar or worse to enabling --precise or --regex. [--before_context=<num>] For logging, number of characters to display before the old match and the new replacement. Default 40. Ignored if not logging. [--after_context=<num>] For logging, number of characters to display after the old match and the new replacement. Default 40. Ignored if not logging.
例子
# Search and replace but skip one column $ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid # Run search/replace operation but dont save in database $ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run # Run case-insensitive regex search/replace operation (slow) $ wp search-replace '[foo id="([0-9]+)"' '[bar id="1"' --regex --regex-flags='i' # Turn your production multisite database into a local dev database $ wp search-replace --url=example.com example.com example.test 'wp_*options' wp_blogs wp_site --network # Search/replace to a SQL file without transforming the database $ wp search-replace foo bar --export=database.sql # Bash script: Search/replace production to development url (multisite compatible) #!/bin/bash if $(wp --url=http://example.com core is-installed --network); then wp search-replace --url=http://example.com 'http://example.com' 'http://example.test' --recurse-objects --network --skip-columns=guid --skip-tables=wp_users else wp search-replace 'http://example.com' 'http://example.test' --recurse-objects --skip-columns=guid --skip-tables=wp_users fi
該軟體包包含在 WP-CLI 本身中,無需額外安裝。
若要透過 WP-CLI 中包含的內容安裝此軟體包的最新版本,請執行:
wp package install [email protected]:wp-cli/search-replace-command.git
我們感謝您主動為此專案做出貢獻。
貢獻不僅限於程式碼。我們鼓勵您以最適合您能力的方式做出貢獻,例如編寫教學課程、在本地聚會上進行演示、幫助其他使用者解決支援問題或修改我們的文件。
更全面的介紹,請查看 WP-CLI 的貢獻指南。該軟體包遵循這些政策和準則。
您認為您發現了錯誤嗎?我們希望您能幫助我們解決問題。
在建立新問題之前,您應該搜尋現有問題以查看是否有現有解決方案,或是否已在較新版本中修復。
一旦您完成一些搜尋並發現您的錯誤沒有未解決或已修復的問題,請建立一個新問題。包含盡可能多的細節,並在可能的情況下明確重現的步驟。如需更多指導,請查看我們的錯誤報告文件。
想貢獻新功能嗎?請先開啟一個新問題來討論該功能是否適合該專案。
一旦您決定花時間查看您的拉取要求,請遵循我們的建立拉取請求指南,以確保這是一次愉快的體驗。有關在本地處理此包的詳細信息,請參閱“設定”。
GitHub 問題不適用於一般支援問題,但您可以嘗試其他地方:https://wp-cli.org/#support
此 README.md 是使用wp scaffold package-readme
(doc) 從專案的程式碼庫動態產生的。若要提出變更建議,請針對程式碼庫的相應部分提交拉取請求。