Mysql的replace函数替换字符串

Linux阅读模式

要把数据库中某个列的所有值中含有”test.linuxeye.com”的字符更换成”www.linuxeye.com”,方法有几种,如shell脚本,但是这样效率非常低,google了几把,发现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/’);

Tue Mar 5 15:12:42 CST 2013

 
  • 本文由 yeho 发表于 2013-03-05
  • 转载请务必保留本文链接:https://linuxeye.com/296.html
MySQL数据库管理常用命令 Linux

MySQL数据库管理常用命令

安装 利用RPM包安装MySQL 设置TCP 3306端口的iptables root密码管理 设置root用户的密码 mysqladmin -uroot password 'password' 修改...