简体   繁体   中英

How to replace bulk href link in mySql database

I have many posts in wordpress. In that post I have links like dev.dev.example.com now I want it to replace with dev.example.com.

I am using following query

UPDATE `dbname`.`wp_posts` SET `post_content`= replace(cast(post_content as varchar(max)), '%dev.dev.example.com%', '') WHERE CONVERT(`post_content` USING utf8) LIKE '%dev.example.com%'

I think it is better to follow wordpress' official guide when moving a wordpress website. http://codex.wordpress.org/Moving_WordPress

Alternatively, as an easy way in your case if you have already done all other steps but stuck in this issue, you can export database to sql file, open in text editor like notepad, use find-and-replace to replace all x.com to y.tom and then import the database. But remember that if domain length is different, you will have some settings lost. It is because wordpress keeps serialized data where length is stored.

Using your way to do via query is not a robust way because some other tables may still have old domain name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM