Categories
MySQL

Trim leading whitespace from a field in MySQL

As always, backup the database or at least the affected table before running a command that will change every record in a table as this does.

The following line will remove the leading spaces (note the parameter '\t'). For new lines use '\n' and for carriage returns use '\r'.

UPDATE members SET memberid = REPLACE(memberid,'\t','');

For more information, see http://stackoverflow.com/questions/281724/does-the-mysql-trim-function-not-trim-line-breaks-or-carriage-returns.