Change and update WordPress URLs in the database when the site is moved to a new host

After migrating a WordPress site to a new URL, either to a live production site or a test development server, the new URL strings in the MySQL database need to be changed and updated in the various database tables of MySQL data.

This method only uses the full MySQL database instead of a WordPress export/import from within and is best suited for a direct swap. So I would copy all the WordPress files/folders to the new destination, set the correct ownership for those files, and then do the database switcheroo.

If youā€™re not comfortable interacting directly with the MySQL database, I suggest you check out and useĀ WP Migrate ProĀ ; otherwise, read on.

Switcheroo WordPress Database

First, do a MySQL database export of the old database on the old server, create a new blank database on the new server, import the old data into PHPMyAdmin orĀ mysql directly on the command lineĀ .

Make sure you have the new database selected, then run some SQL update and replace commands on the tables, in particular wp_options, wp_posts, wp_postmeta.

Use the code as shown below and swap your old and new URLs, without forward slashes. Also if needed, change the table prefix values where applicable (that is to say, wp_)

ACTUALIZAR wp_options SET option_value = replace (option_value, 'http: //www.oldurl', 'http: //www.newurl') DONDE option_name = 'home' O option_name = 'siteurl'; 

ACTUALIZAR wp_posts SET guid = replace (guid, 'http: //www.oldurl','http: //www.newurl');

ACTUALIZAR wp_posts SET post_content = replace (post_content, 'http: //www.oldurl', 'http: //www.newurl');

ACTUALIZACIƓN wp_postmeta SET meta_value = replace (meta_value, 'http: //

or via command line:

nombre de usuario @ [~ / Escritorio]: mysql -u root -p databasename Introducir la contraseƱa: 

Leer la informaciĆ³n de la tabla para completar los nombres de tablas y columnas Puede desactivar esta funciĆ³n para obtener un inicio mĆ”s rĆ”pido con -A

Bienvenido al monitor MySQL. Los comandos terminan con; o g. Su ID de conexiĆ³n de MySQL es 892 VersiĆ³n del servidor: 5.5.13 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle y / o sus filiales. Todos los derechos reservados.

Oracle es una marca registrada de Oracle Corporation y / o su afiliados Otros nombres pueden ser marcas registradas de sus respectivos propietarios

Escriba 'ayuda'; o 'h' para ayuda. Escriba 'c' para borrar la declaraciĆ³n de entrada actual.

mysql> ACTUALIZAR wp_options SET option_value = replace (option_value, 'http: //www.oldurl', 'http: //www.newurl') DONDE option_name = 'home' O option_name = 'siteurl'; Consulta OK, 0 filas afectadas (0.00 seg) Filas emparejadas: 2 Cambiado: 0 Advertencias: 0

mysql> ACTUALIZAR wp_posts SET guid = replace (guid, 'http: //www.oldurl','http: //www.newurl'); Consulta OK, 0 filas afectadas (0.02 seg) Filas emparejadas: 964 Cambiado: 0 Advertencias: 0

mysql> ACTUALIZAR wp_posts SET post_content = replace (post_content, 'http: //www.oldurl', 'http: //www.newurl'); Consulta OK, 0 filas afectadas (0.05 seg) Filas emparejadas: 964 Cambiado: 0 Advertencias: 0

mysql> ACTUALIZAR wp_postmeta SET meta_value = replace (meta_value, 'http: //www.oldurl','http: //www.newurl'); g Consulta OK, 0 filas afectadas (0.01 seg) Filas emparejadas: 686 Cambiado: 0 Advertencias: 0


Finally, update your WordPress config file to reflect the new database, wp-config.phpā€, which should be in the root of your web document: change, database name, username, password, and host values:

define ('DB_NAME', 'databasename'); 
/ ** Nombre de usuario de la base de datos MySQL * /
define ('DB_USER', 'nombre de usuario');
/ ** ContraseƱa de la base de datos MySQL * /
define ('DB_PASSWORD', 'contraseƱa');
/ ** Nombre de host MySQL * / define ('DB_HOST', 'localhost');

Now everything should fit perfectly.

djaveĀ Ā has created a nice and easy script that takes theĀ URL old and newĀ and hands you the SQL code for the WordPress exchange, good!

serialized data

Sometimes problems can arise with a problem called serialized data, which is when a PHP data array is sort of encrypted with the actual URL, so if the URL is changed, the data is gone.

There are 2 brilliant tools that can handle serialized data and do a search and replace on the old and new database of the URL and leave the serialized data intact.

interconnect

First of all, there is a script that is executed by loading and looking for it after migrating and importing your old database to the new one. This will make the necessary changes. get it fromĀ hereĀ .

WP Migrate Pro

The second is a proven and robust plugin that you install on your original site and run from there to find and replace on the URL string and Webroot, a new database dump is exported and that is the one that imports into the new database URL hosted data.Ā WP Migrate ProĀ can find and replace data within serialized arrays.Ā get it hereĀ .

Scroll to Top