https://static.iklfy.com/static/images/index/23.jpg

MYSQL字符替换语句

mysql> update `table_name` set field = replace(field,'.rar','.7z');

table_name:要查询的表名,
field:表里的字段名,
replace(field,'.rar','.7z'); :正则匹配,把field字段里的 .rar 替换为 .7z
https://static.iklfy.com/static/images/index/9.jpg

mysql查询替换语句

UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` LIKE '%from_str%'

说明:
table_name —— 表的名字
field_name —— 字段名
from_str —— 需要替换的字符串
to_str —— 替换成的字符串
下面是今天运行的两句SQL批量替换语句,如果用到的可以参考下!
 UPDATE boblog_blogs SET content = replace (content,'[mycode=xml]','[mycode=html]');

查询表 boblog_blogs 将 content 字段中的字符 [mycode=xml> 替换成 [mycode=html>
 UPDATE boblog_blogs SET content = replace (content,'[//mycode]','[/mycode]');

查询表 boblog_blogs 将 content 字段中的字符 [//mycode> 替换成 [/mycode>
UPDATE boblog_blogs SET htmlstat=0 where htmlstat=1

查询表 boblog_blogs 将 htmlstat 字段中的值 0 替换成 1