Search and replace MySQL content

Today I switched from the Code Markup to the Code Snippet WordPress plugin. Therefore I had to change the way the code block is activated. This is a time consuming job if you have to do this by hand, so I figured out there should be a smarter way of doing this. Check out the MySQL replace function below:

update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');

And so the above translated to the lines I needed:

mysql> update wp_vleeuwen_posts set post_content = replace(post_content, '

', ''); Query OK, 35 rows affected (0.06 sec) Rows matched: 72 Changed: 35 Warnings: 0 mysql> update wp_vleeuwen_posts set post_content = replace(post_content, '
', '[/ code]'); Query OK, 35 rows affected (0.01 sec) Rows matched: 72 Changed: 35 Warnings: 0 mysql>

Notice the little typo I had to make in order to let the above code snippet work ([/ code]).