在MySQL数据库中替换\n\r。

时间:2021-02-23 09:37:24

How can I replace \n\r in fields inside my database with a new line? This data was from a previous table which has the column type set wrong.

如何用一个新行来在我的数据库内的字段中替换\n\r ?此数据来自前面的表,该表的列类型设置错误。

1 个解决方案

#1


1  

This should work

这应该工作

UPDATE `table` SET `column` = REPLACE(`column`, '\\r\\n', '\r\n');

nevertheless do a backup before you try!

然而,在你尝试之前做一个备份!

You might want to replace single occurrences after that too:

你可能想要在那之后替换单个事件:

UPDATE `table` SET `column` = REPLACE(`column`, '\\n', '\n');
UPDATE `table` SET `column` = REPLACE(`column`, '\\r', '\r');

Since not all OS use \r\n as combination for line breaks.

因为不是所有的操作系统都使用\r\n作为换行的组合。

#1


1  

This should work

这应该工作

UPDATE `table` SET `column` = REPLACE(`column`, '\\r\\n', '\r\n');

nevertheless do a backup before you try!

然而,在你尝试之前做一个备份!

You might want to replace single occurrences after that too:

你可能想要在那之后替换单个事件:

UPDATE `table` SET `column` = REPLACE(`column`, '\\n', '\n');
UPDATE `table` SET `column` = REPLACE(`column`, '\\r', '\r');

Since not all OS use \r\n as combination for line breaks.

因为不是所有的操作系统都使用\r\n作为换行的组合。