Use the REPLACE()
method, which can replace every occurrence of a character by another:
UPDATE foo SET field2 = REPLACE(field2, ' ', '');
This query will remove every spaces in the field2
column.
Definition of the method, from the MySQL doc:
Returns the string str with all occurrences of the string *from_str* replaced by the string *to_str*.
REPLACE()
performs a case-sensitive match when searching for *from_str*.mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww'); -> 'WwWwWw.mysql.com'
This function is multi-byte safe.