很多时候在做资源迁移的时候,路径改变,存在数据库的资源文件的路径也会跟着改变,所以需要替换存放路径的字符串,如何快速的替换表中的字段的这些字符串呢?
1. 可以通过MySQL的replace函数
replace(object,search,replace)
把object中出现search的全部替换为replace
update tablename set 字段名1=replace(字段名, 原字符串1,替换字符串1) ,字段名1=replace(字段名2, 原字符串,替换字符串2)......:
UPDATE t_exam SET video_url=REPLACE(video_url,'./Public/Uploads/','./Public/Uploads2/'),thumb=REPLACE(thumb, './Public/Uploads/', './Public/Uploads2/') where UNIX_TIMESTAMP(create_time) < UNIX_TIMESTAMP('2018-05-30 00:00:00');
或者:
UPDATE t_exam_new SET video_url=REPLACE(video_url, './Public/Uploads/', './Public/Uploads2/'), thumb=REPLACE(thumb, './Public/Uploads/', './Public/Uploads2/') where UNIX_TIMESTAMP(create_time) < UNIX_TIMESTAMP(str_to_date('30/5/2018 00:00:00', '%d/%m/%Y %H:%i:%s'));