Should I change multiple text fields values via MySQL or is there any other preferable way? The site has a content type and this content type has two fields:


Text Field
Term Reference Field


There are thousands of nodes on this content type and I want to change some values (find/replace).

For example, I want to change all the "ABCD" strings with the "WXYZ" strings on the text fields in all the nodes.

Is it a good way to do this change via MySQL or is there any other preferable way? (Both text field change and taxonomy term replacement).

Note: I saw the Search and Replace Scanner module but it gives some errors I couldn't understand why. And it gives timeout error for a large amount of nodes.
The Drupal way is to iterate over the nodes of interest and modify the fields. Here is a simple example that shows how you could make modifications in the Body field of the Article content type:

  $nodes = node_load_multiple(array(), array('type' =&gt; 'article'));
  foreach($nodes as $node) {
    // Only modify nodes that have something in the body field
    if (isset($node-&gt;body[$node-&gt;language][0]['value'])) {

      $text = $node-&gt;body[$node-&gt;language][0]['value'];
      $find = 'ABCD';
      $replace = 'WXYZ';
      $text = str_replace($find, $replace, $text);
      $node-&gt;body[$node-&gt;language][0]['value'] = $text;
      node_save($node);
    } 
  }


One thing to note about doing it this way is the last-modified time of all your nodes will be updated. You may or may not want this. If you want to update the nodes without changing the timestamp, use this instead:

  $nodes = node_load_multiple(array(), array('type' =&gt; 'article'));
  foreach($nodes as $node) {
    // Only modify nodes that have something in the body field
    if (isset($node-&gt;body[$node-&gt;language][0]['value'])) {

      $text = $node-&gt;body[$node-&gt;language][0]['value'];
      $find = 'ABCD';
      $replace = 'WXYZ';
      $text = str_replace($find, $replace, $text);
      $node-&gt;body[$node-&gt;language][0]['value'] = $text;
      unset($node-&gt;created);
      unset($node-&gt;updated);
      field_attach_update('node', $node);
    } 
  }


Edit: How to modify taxonomy terms

You could use the same approach to modify taxonomy terms, i.e. load the terms, iterate over them, and do a find/replace on each.

  $vocab = taxonomy_vocabulary_machine_name_load('my_vocabulary');
  $terms = entity_load('taxonomy_term', FALSE, array('vid' =&gt; $vocab-&gt;vid));

  foreach ($terms as $term) {
    $text = $term-&gt;name;
    $find = 'ABCD';
    $replace = 'WXYZ';
    $text = str_replace($find, $replace, $text);
    $term-&gt;name = $text;
    taxonomy_term_save($term);
  }


Depending on how expert you are with MySQL, you could try updating the database field directly and you might have success, but it's prone to error especially if your fields have revisions.