h1

replace syntax in mysql

November 3, 2011

The mysql REPLACE syntax allows you to do string replacements within the content of mysql table text fields. One application I used recently was to rewrite links in blocks of text entered into the Druapl CMS.

UPDATE table SET col = REPLACE(col, '/some/path', '/some/other/path');

This will replace all instances of ‘/some/path’ with ‘/some/other/path’ within the col column of the table table.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: