搜索&将数据库中的“http"替换为“https" [英] Search & replace 'http' to 'https' in database

查看:35
本文介绍了搜索&将数据库中的“http"替换为“https"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 phpmyadmin,我想运行一个查询来搜索我的整个数据库:

Using phpmyadmin, I want to run a query that will search my entire database for:

http://example.com

并替换为:

https://example.com

我的 SQL 知识有限,大概是这样的:

My SQL knowledge is limited, maybe something like:

UPDATE ?? = REPLACE(??, 'http://example.com', 'https://example.com');

数据库超过 1GB,所以我可以运行什么不会使服务器崩溃.

The database is over 1gb, so what can I run that will not crash the server.

更新:请注意,虽然在 SO 上发布了其他有关搜索和替换的答案,但它们似乎并未涵盖整个数据库.

Update: Note that while there are other answers posted here on SO that deals with search and replace, they don't seem to cover the entire database.

推荐答案

使用 REPLACE.如果字段上有索引,则 UPDATE 可以使用它们

use REPLACE. and if there is a index on the field then the UPDATE can use them

UPDATE t
     set url = REPLACE(url, 'http:', 'https:')
     WHERE url LIKE '%http:%';

只更改example.com

这只会找到带有 'http://example.com' 的行

this will only find row with 'http://example.com'

UPDATE t
     set url = REPLACE(url, 'http:', 'https:')
     WHERE url LIKE '%http://example.com%';

或者这会找到所有带有 http://的行,但只将这个 http://example.com 更改为https://example.com

or this will find all rows with http:// but only change only this http://example.com to https://example.com

UPDATE t
     set url = REPLACE(url, 'http://example.com', 'https://example.com')
     WHERE url LIKE '%http:%';

这篇关于搜索&将数据库中的“http"替换为“https"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆