Enter Search Query:

  • 1157
  • Close

Find and replace with SQL

I recently changed the document root on my webserver. Subsequently I found that some of my WordPress blogs store the document root in the database (i.e. tables for wp_options, wp_commentmeta, etc.). To fix this I had to run some SQL queries on my WP databases to change the document root from the old /home/dvielmet/ to the new /home/www/. Here’s how:

The SQL query used:

[sql]update wp_commentmeta set meta_value = replace(meta_value, ‘/home/dvielmet/’, ‘/home/www/’);[/sql]

More generally the query would be:

[sql]update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this’, ‘and replace it with this’);[/sql]

That’s it.

June 18, 2011

Related Posts