---
title: "Instrucción Replace en MySQL"
date: 2011-11-14
author: "Alex Borrás"
source: https://alexborras.com/instruccion-replace-en-mysql/
site: "El Blog de Alex Borrás"
---

# Instrucción Replace en MySQL

[![](https://alexborras.com/wp-content/uploads/2011/11/mysql.jpg)](https://alexborras.com/wp-content/uploads/2011/11/mysql.jpg)Los que se manejen con WordPress y MySQL es posible que se encuentre en la necesidad de realizar una modificación masiva de caracteres o palabras en una base de datos.

La instrucción para realizarlo es la siguiente, el ejemplo se basa en modificar el contenido de una entrada de WordPress:

\[SQL\]  

update wp\_posts set post\_content = replace(post\_content, ‘Mi cadena’,’Nueva Cadena’);  

\[/SQL\]

Esta instrucción me ha sido especialmente útil en una migración de una base de datos de un servidor Windows a otro Linux donde por un tema de codificación no quedaron bien los acentos, ñ’s y demás caracteres.

Este es el Script de traspaso completo:

\[SQL\]  

update wp\_posts set post\_content = replace(post\_content, ‘Ã¡’,’á’);  

update wp\_posts set post\_content = replace(post\_content, ‘Ã©’,’é’);  

update wp\_posts set post\_content = replace(post\_content, ‘í©’,’é’);  

update wp\_posts set post\_content = replace(post\_content, ‘í¨’,’è’);  

update wp\_posts set post\_content = replace(post\_content, ‘Ã’,’í’);  

update wp\_posts set post\_content = replace(post\_content, ‘í³’,’ó’);  

update wp\_posts set post\_content = replace(post\_content, ‘Ã³’,’ó’);  

update wp\_posts set post\_content = replace(post\_content, ‘í²’,’ò’);  

update wp\_posts set post\_content = replace(post\_content, ‘íº’,’ú’);

update wp\_posts set post\_content = replace(post\_content, ‘Ã±’,’ñ’);  

update wp\_posts set post\_content = replace(post\_content, ‘í±’,’ñ’);  

update wp\_posts set post\_content = replace(post\_content, ‘Âº’,’º’);  

update wp\_posts set post\_content = replace(post\_content, ‘Âª’,’ª’);  

update wp\_posts set post\_content = replace(post\_content, ‘â‚¬’,’€’);

update wp\_posts set post\_title = replace(post\_title, ‘Ã¡’,’á’);  

update wp\_posts set post\_title = replace(post\_title, ‘Ã’,’í’);  

update wp\_posts set post\_title = replace(post\_title, ‘Ã©’,’é’);  

update wp\_posts set post\_title = replace(post\_title, ‘í©’,’é’);  

update wp\_posts set post\_title = replace(post\_title, ‘í¨’,’è’);  

update wp\_posts set post\_title = replace(post\_title, ‘Ã³’,’ó’);  

update wp\_posts set post\_title = replace(post\_title, ‘í³’,’ó’);  

update wp\_posts set post\_title = replace(post\_title, ‘í²’,’ò’);  

update wp\_posts set post\_title = replace(post\_title, ‘íº’,’ú’);

update wp\_posts set post\_title = replace(post\_title, ‘Âº’,’º’);  

update wp\_posts set post\_title = replace(post\_title, ‘Âª’,’ª’);  

update wp\_posts set post\_title = replace(post\_title, ‘Ã±’,’ñ’);  

update wp\_posts set post\_title = replace(post\_title, ‘í±’,’ñ’);  

update wp\_posts set post\_title = replace(post\_title, ‘â‚¬’,’€’);

\[/SQL\]
