interconnectit / search-replace-db
一款用于快速在整个数据库中修改字符串的PHP搜索替换工具。在将WordPress网站从开发环境迁移到生产环境时,更改基本URL非常有用。
Requires
- php: >=7.1
- ext-json: *
- ext-mbstring: *
- ext-mysqli: *
- ext-pdo: *
Requires (Dev)
- ext-simplexml: *
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2024-09-14 15:21:53 UTC
README
搜索替换数据库 - v4.1.3
此脚本是为了协助迁移基于PHP和MySQL的网站。适用于大多数常见的CMS。
如果你发现任何问题,请在问题区域告诉我们,如果你能改进代码,请分叉存储库并给我们发送pull request :)
新增功能
- 支持通过Travis CI进行持续集成
- 能够执行多次搜索替换
- 能够排除表
- 移除WP的特定加载器
- 不再自动填充数据库字段,这可能会使用户的网站上留下脚本导致安全问题
- 脚本现在检查是否使用了正确的PHP版本
- 脚本检查是否安装了必要的模块
- 脚本检查连接是否安全,如果不安全则给出警告
- 错误修复
- 用户界面调整
- 在CLI中密码不是必需的
- 能够使用SSL连接,仅限命令行功能
警告和限制
尽管我们尽力测试所有可能的情况,但我们无法测试每一个。备份和验证非常重要。
您自行承担使用此脚本的风险,我们不对可能引起的问题承担责任。
存在许多边缘情况和喜欢干扰数据库的WordPress插件,我们并没有灵丹妙药。
本软件的许可证为GPL v3,如果您在贡献或分叉时请记住这一点。
请备份,也要备份,最后还要备份!
用法
- 备份。
- 迁移您网站的所有文件。
- 将脚本文件夹上传到您的网站根目录或更高目录。
- 在您的网页浏览器中浏览到脚本文件夹的URL。
- 根据需要填写字段。
- 选择
执行安全测试运行
按钮,进行不搜索/替换的测试运行。
安装
要安装脚本,请将文件放置在您的网站公共文件夹中,然后转到您的网站URL/Search-Replace-DB。
CLI脚本
要调用脚本,请在您的shell中导航到安装Search Replace DB的目录。
输入php srdb.cli.php
来运行程序。输入php srdb.cli.php --help
以获取用法信息。
-h, --host
Required. The hostname of the database server.
-n, --name
Required. Database name.
-u, --user
Required. Database user.
-p, --pass
Database user's password.
-P, --port
Optional. Port on database server to connect to. The default is
3306. (MySQL default port).
-s, --search
String to search for or `preg_replace()` style regular
expression.
-r, --replace
None empty string to replace search with or `preg_replace()`
style replacement.
-t, --tables
If set only runs the script on the specified table, comma
separate for multiple values.
-w, --exclude-tables
If set excluded the specified tables, comma separate for multuple
values.
-i, --include-cols
If set only runs the script on the specified columns, comma
separate for multiple values.
-x, --exclude-cols
If set excludes the specified columns, comma separate for
multiple values.
-g, --regex [no value]
Treats value for -s or --search as a regular expression and -r or
--replace as a regular expression replacement.
-l, --pagesize
How rows to fetch at a time from a table.
-z, --dry-run [no value]
Prevents any updates happening so you can preview the number of
changes to be made
-e, --alter-engine
Changes the database table to the specified database engine eg.
InnoDB or MyISAM. If specified search/replace arguments are
ignored. They will not be run simultaneously.
-a, --alter-collation
Changes the database table to the specified collation eg.
utf8_unicode_ci. If specified search/replace arguments are
ignored. They will not be run simultaneously.
-v, --verbose [true|false]
Defaults to true, can be set to false to run script silently.
--debug [true|false]
Defaults to false, prints more verbose errors.
--ssl-key
Define the path to the SSL KEY file.
--ssl-cert
Define the path to the SSL certificate file.
--ssl-ca
Define the path to the certificate authority file.
--ssl-ca-dir
Define the path to a directory that contains trusted SSL CA
certificates in PEM format.
--ssl-cipher
Define the cipher to use for SSL.
--ssl-check [true|false]
Check the SSL certificate, default to True.
--allow-old-php [true|false]
Suppress the check for PHP version, use it at your own risk!
--help
Displays this help message ;)
示例CLI命令
php srdb.cli.php -h dbhost -n dbname -u root -p "" -s "http://www.yourdomain.com" -r "http://newdomain.com" php srdb.cli.php -h dbhost -n dbname -u root -p "password" -s "http://www.yourdomain.com" -r "http://newdomain.com" php srdb.cli.php -h dbhost -n dbname -u root -p "password" -s "search" -r "replace"
故障排除
搜索/替换操作后没有任何东西工作!
现在是时候使用您的备份了!
我收到一个弹出窗口,说有AJAX错误
这偶尔会发生,可能有几个原因
-
脚本开始时,它会尝试启动您的WordPress或Drupal安装以自动检测您的用户名和密码设置。如果失败,您将看到一条消息告知您自动检测失败。您将需要手动输入详细信息。
-
脚本无法设置超时,因此PHP在表处理之前关闭了连接,这在某些服务器配置中可能发生。
贡献
您可以通过GitHub查看源代码并提交pull request,项目页面位于
https://github.com/interconnectit/Search-Replace-DB/
我们赞赏代码中的一小部分unittest,请解释您试图解决什么问题。
许可证
此文件是Search-Replace-DB的一部分。
Search-Replace-DB 是免费软件:您可以按照自由软件基金会发布的GNU通用公共许可证的条款重新分发和/或修改它,无论是许可证的第3版还是任何后续版本。
Search-Replace-DB 的分发是希望它会有用,但没有任何保证;甚至没有关于其可销售性或适用于特定目的的暗示性保证。有关更多详细信息,请参阅GNU通用公共许可证。
您应该已经随 Search-Replace-DB 收到了GNU通用公共许可证的副本。如果没有,请参阅https://gnu.ac.cn/licenses/。