售前咨询
技术支持
渠道合作

Mysql的replace函数替换字符串

要把数据库中某个列的所有值中含有”test.linuxeye.com”的字符更换成”www.linuxeye.com”,方法有几种,如shell脚本,但是这样效率非常低,但Mysql中有replace函数很容易实现替换。

replace(str,from_str,to_str)

在字符串 str 中所有出现的字符串 from_str 均被to_str替换,然后返回这个字符串

如你要将表wp_posts里面的guid字段的http://test.linuxeye.com/…替换为http://www.linuxeye.com/…:

update wp_posts set guid=replace(guid,’http://test.linuxeye.com/’,’http://www.linuxeye.com/’);

上一篇:

下一篇:

相关文章