• UID12
  • 登录2016-06-14
  • 粉丝110
  • 关注50
  • 发帖1415
  • 主页
  • 金币8520枚
社区居民
最爱沙发
忠实会员
喜欢达人
原创写手
极分享 发布于2016-06-02 11:03
1/692

网站迁移利器:数据库中的查找替换

楼层直达

Search Replace DB

源码:https://github.com/interconnectit/Search-Replace-DB

 

This script was made to aid the process of migrating PHP and MySQL based websites. It has additional features for WordPress and Drupal but works for most other similar CMSes.

If you find a problem let us know in the issues area and if you can improve the code then please fork the repository and send us a pull request :)

Warnings & Limitations

  1. Three character UTF8 seems to break in certain cases.
  2. We can't test every possible case, though we do our best. Backups and verifications are important.
  3. The license for this script is GPL v3 and no longer WTFPL. Please bear this in mind if contributing or branching.
  4. You use this script at your own risk and we have no responsibility for any problems it may cause.
  5. Do backups.

Usage

  1. Do backups.
  2. Migrate all your website files.
  3. Upload the script folder to your web root or higher.
  4. Browse to the script folder URL in your web browser.
  5. Fill in the fields as needed.
  6. Choose the Dry run button to do a dry run without searching/replacing.

Installation

If you would like Search Replace DB to detect your WordPress installation, you should install it within a new subfolder within your WordPress installation.

For example, if you have

/website.com/index.php

/website.com/wp-config.php

/website.com/wordpress/

/website.com/wordpress/index.php

/website.com/wordpress/wp-settings.php

etc.

You can copy Search Replace DB into the following location:

/website.com/wordpress/Search-Replace-DB/

/website.com/wordpress/Search-Replace-DB/index.php

/website.com/wordpress/Search-Replace-DB/srdb.class.php

/website.com/wordpress/Search-Replace-DB/srdb.cli.php

etc.

CLI script

To invoke the script, nagivate in your shell to the directory to where you installed Search Replace DB.

Type php srdb.cli.php to run the program. Type php srdb.cli.php --help for usage information:

-h, --host

    Required. The hostname of the database server.

-n, --name

    Required. Database name.

-u, --user

    Required. Database user.

-p, --pass

    Required. Database user's password.

--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.

-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 many 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.

--help

    Displays this help message ;)

Troubleshooting

I get a popup saying there was an AJAX error

This happens occasionally and could be for a couple of reasons:

  • When the script starts, it attempts to start your WordPress or Drupal installation to auto-detect your username and password settings. If this fails, you will see a message informing you that auto-detection failed. You will have to enter your details manually.
  • Script was unable to set the timeout so PHP closed the connection before the table could be processed, this can happen on some server configurations.
  • When using php-fpm (as you have with VVV) make sure that the socket is owned by the server user chown www-data:www-data /var/run/php5-fpm.sock.

0人打赏
  • UID7461
  • 登录2016-06-08
  • 粉丝1
  • 关注0
  • 发帖211
  • 主页
  • 金币191枚
社区居民
忠实会员
android_chao 发布于2016-06-03 11:17
沙发F
支持分享
您需要登录后才可以回帖
发表回复
极贡献
技术问答
专题荟萃
程序人生
视觉设计
Android开发
iOS开发
编程语言
前端开发
后端开发
服务器架构
软件测试
运维方案
创业路上



最热文章墙

  • 60412/343   【精品推荐】200多种Android动画效果的强悍框架,太全了,不看这个,再有动画的问题,不理你了^@^

  • 33622/188   情人节福利,程序员表白的正确姿势:改几行代码就变成自己的表白了

  • 32039/141   省时省力的Android组件群来了,非常棒的原型参考

  • 29311/226   【精品推荐】Android版产品级的音乐播放器源码,功能太强大了,最好的产品原型有木有?

  • 26282/2   超全!整理常用的iOS第三方资源

  • 26140/0   Python爬虫:常用浏览器的useragent

  • 24819/70   原创表白APP,以程序员的姿势备战新年后的7夕,持续完善中!

  • 23128/138   2016抢红包软件及源码

  • 20031/29   麻省理工的一帮疯子,真的实现了随意操控万物!(绝对黑科技)

  • 19868/25   Android工程师面试题大全

  • 19292/27   2016程序员跳槽全攻略

  • 19077/9   GitHub上排名前50的iOS项目:总有一款你用得着

  • 18567/20   码魂:程序员的牛B漫画

  • 16996/149   Android版类似UC浏览器:非常赞,产品级的源码

  • 16916/3   吐槽那些程序员的搞笑牛逼注释

  • 15745/1   iOS 动画总结

  • 15468/10   2016年最全的Android面试考题+答案 精编版

  • 15321/41   一个绚丽的loading动效分析与实现!

  • 14892/73   【持续更新中】Android福利贴(二):资料源码大放送

  • 14851/83   Android小而全的博客源码:非常适合全面掌握开发技巧

  • 14721/10   女程序员的梦,众网友的神回复

  • 14602/44   惊艳的App引导页:背景图片切换加各个页面动画效果

  • 14513/11   年会上现场review代码是怎么样的体验!

  • 14282/23   个人收集的Android 各类功能源代码

  • 14164/5   新一代Android渠道打包工具:1000个渠道包只需要5秒

  • 13346/19   珍藏多年的素材,灵感搜寻网站

  • 13315/53   基于瀑布流的美女图片浏览App,有注释的源代码

  • 12957/17   用JavaScript 来开发iOS和Android 原生应用:React Native开源框架中文版来啦

  • 12848/74   仿京东商城客户端Android最新版,不错的原型和学习资料

  • 12810/15   基于Android支付宝支付设计和开发方案

  • 12587/20   Android福利第三波【Android电子书】

  • 12387/17   什么是真正的黑客:收获12200+Stars,人气远超微软开源VS

  • 12301/94   Android带弹幕的视频播放器源码,来自大名鼎鼎的Bilibili弹幕网站

  • 12246/18   65条最常用正则表达式,你要的都在这里了

  • 12127/70   【精品推荐】类似360安全卫士安Android源码:非常赞的产品原型

  • 11780/7   用程序员的姿势抢过年的火车票

  • 11729/0   iOS中文版资源库,非常全

  • 11716/7   一张图搞定iOS学习路线,非常全面

  • 11693/11   有木有这样一张酷图帮你集齐所有git命令超实用

  • 11210/10   成为Java顶尖程序员 ,看这11本书就够了

  • 10973/18   一张图搞定Android学习路线,非常全面

  • 10883/10   微信支付终于成功了(安卓,iOS),在此分享

  • 10580/44   在线音乐播放器完整版(商用级的源码):非常赞,可听免费高品质专辑

  • 10525/3   基于Node.js的强大爬虫,能直接发布抓取的文章哦

  • 10430/29   【持续更新中】Android福利贴(一):资料源码

  • 10407/0   GitHub iOS 库和框架Top100 

  • 9984/4   46 个非常有用的 PHP 代码片段

  • 9741/3   即时通信第三方库

  • 9712/61   【技巧一】搭配Android Studio,如何实现App远程真机debug?

  • 9545/9   烧了5亿美金,这家神秘的公司即将颠覆人类未来!

  • 9508/8   流媒体视频直播方案

  • 9389/9   B站建开源工作组:APP想支持炫酷弹幕的看过来

  • 9251/18   八个最优秀的Android Studio插件

  • 9197/2   【精品推荐】高质量PHP代码的50个实用技巧:非常值得收藏

  • 9113/9   中国黑客的隐秘江湖:攻守对立,顶尖高手月入千万美元

  • 8682/6   开箱即用!Android四款系统架构工具

  • 8567/3   一张图看清Linux 内核运行原理

  • 8468/10   十大技巧快速提升Android应用开发性能

  • 8448/3   10款GitHub上最火爆的国产开源项目——可以媲美西半球

  • 8136/1   Android性能优化视频,文档以及工具

  • 返回顶部