Skip to content

Instantly share code, notes, and snippets.

@Chocksy
Last active March 3, 2020 12:53
Show Gist options
  • Save Chocksy/36135f7954c4ba65815bf825f25ff94f to your computer and use it in GitHub Desktop.
Save Chocksy/36135f7954c4ba65815bf825f25ff94f to your computer and use it in GitHub Desktop.
Wordpress DB migration (via queries)

DB migration WP

  • export the wp_posts, wp_postmeta tables from the old DB.
  • import the exported data into 2 new tables wp_old_posts, wp_old_postmeta into the new DB.
  • change collation on the table from utf8mb4_unicode_ci to utf8mb4_unicode_520_ci
  • add to the current/new table a column old_id (to store the id of the row in the old table. In our case wp_posts)
  • make a similar query to this:
INSERT INTO wp_posts (old_id, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count) 
SELECT * FROM wp_old_posts;

INSERT INTO wp_postmeta (post_id, meta_key, meta_value) 
SELECT wp_posts.ID, meta_key, meta_value FROM wp_old_postmeta 
INNER JOIN wp_posts ON wp_posts.old_id = wp_old_postmeta.post_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment