# PhpMyAdmin批量替换字段内容的SQL命令

```
UPDATE 表名 SET 字段名 = replace(字段名,'原来的内容','替换后的内容')
```

举一个例子,就是我实际操作的时候的命令:

```
UPDATE cpg1410_pictures SET filepath=replace(filepath,'wallpapers/art/','wallpapers/beautiful/art/')
```

应用： 比如本博客更换了域名，现需要将所有文章中的图片链接地址更新为新域名，就需要将Typecho文章中的原域名 “<https://true-me.com”> 全部替换成现 “<https://chujian.xyz”，>

那么替换语句为：

```
UPDATE typecho_contents SET text = replace(text, 'https://true-me.com', 'https://chujian.xyz')
```

再比如如将WordPress文章中的 “搜索引擎优化” 全部替换成 “搜索引擎营销” ，替换语句为：

```
UPDATE wp_posts SET post_content = replace(post_content, '搜索引擎优化', '搜索引擎营销');
```

语句中还可以加入替换条件，如只替换限定ID小于200的内容：

UPDATE 数据表名 SET 字段名 = replace(字段名, '要替换的字符串', '替换为') WHERE 设定条件;

```
UPDATE wp_posts SET post_content = replace(post_content, '搜索引擎优化', '搜索引擎营销') WHERE ID < 200;
```

来源：<https://san.ci/95.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.linh.eu.org/jian-zhan-ji-shu/phpmyadmin-pi-liang-ti-huan-zi-duan-nei-rong-de-sql-ming-ling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
