How to replace a string in Mysql table field

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


13 points

I have some hardcoded information in my database fields. I want to replace them with empty strings. What is the best way to replace those fields?



17 points

You can use Mysql replace as follows:

UPDATE table SET field = REPLACE(field, 'string-to-be-replaced', 'string-replaced') 

Like in Drupal, if I have to replace a string (say, alpha2) in body of the content. I would replace body field in node_revisions table as follows:

UPDATE node_revisions SET body = REPLACE(body, 'alpha2', '') 

Anonymous's picture
Created by Anonymous
0 points

You can find more detail here: Mysql String replace.

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.