mysql批量替换指定字段字符串语句
update 数据表名 set 字段名 = replace(字段名, '要替换的字符串', '替换为') where 设定条件;
例子:
update `cdb_laowei` set `field_laowei` = replace (`field_laowei`,'from_str','to_str')
cdb_laowei —— 该字符或字符串所在表的名字
field_laowei —— 该字符或字符串所在字段的字段名
from_str —— 需要替换的字符串
to_str —— 替换成的字符串
例如:
进入phpmyadmin,打开要操作的数据库,点击上方的sql,执行以下sql语句:
update `pre_forum_post` set `author` = replace( `author` , '老威博客', '老威' )
意思是把用户名“老威博客”修改为“老威”,其中pre_要修改为您自己数据库的表前缀。
update phpcms_article set title=replace(title,'[2009]','〔2009〕');
update phpcms_article set content=replace(content,'[2009]','〔2009〕');
语句中还可以加入替换条件,如只替换限定id小于200的内容:
update wp_posts set post_content = replace(post_content, '搜索引擎优化', '搜索引擎营销') where id < 200;
后面附一个高级点的
update `cdb_settings` set `value` = '' where convert( `variable` using utf8 ) ='adminipaccess' limit 1 ;