WordPress – playing with MySQL database

This post is for myself. I usually like to change database and forget the commands. So this is a reference sheet for me while dealing with my WordPress database.mysql

There usually are 11 default tables – with “wp_” prefix.

wp_options is the one I usually deal with while changing the directory, website address and so on.

Renaming tables

RENAME TABLE old_posts TO wp_posts;

Merging two tables (when I manually merge posts from two separate blogs. )

CREATE TABLE wp_post_merged SELECT DISTINCT * FROM (SELECT * FROM wp_post_1 UNION ALL SELECT * FROM wp_post_2) sq;

Replacing a text string in a table


UPDATE table_name SET column_name = replace(column_name, 'DeleteThis', 'AddThis');

UPDATE wp_posts SET post_content = replace(post_content, 'Apple computers', 'MS computers');



0 thoughts on “WordPress – playing with MySQL database

  1. Find & Replace Data in MySQL

    To find a string in a certain field and replace it with another string:

    update [table_name] set [field_name] = replace([field_name],'[string_to_find]’,'[string_to_replace]’);

Leave a Reply

Your email address will not be published. Required fields are marked *