WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm exporting a Wordpress site from localhost to a web host, and I am unable to import the Media Library, as the web host is unable to contact localhost.

I've uploaded all of the localhost files from /wp-content/uploads/..., and I'm thinking I just need to isolate the part of the MySQL database which contains the Media Library, and adjust the URL, then import the SQL into the web host database.

Can you tell me where the Media Library lives in the MySQL database please?

share|improve this question
up vote 4 down vote accepted

The Media Library lives in both wp_posts and wp_postmeta.

  • wp_postmeta contains the image URL
  • wp_posts contains an entry for each image insertion into a post, along with the post ID.

Exporting and importing these 2 tables as SQL did not work for me - I received 'duplicate entry for key 7'...

Exporting and importing these 2 tables as CSV did work, using "CSV using load data".

Before importing, I emptied the 2 tables in the recipient database.

share|improve this answer
Select * from wp_posts where post_type = 'attachment';

Will return all the entries off media library. After the execution, you can export the result table as SQL or CSV or any other portable data format you like. Remember if you not sure the entries exist in database, use Insert IGNORE statement instead of INSERT. (Possible through exporting pan in phpMyAdmin or other MySQL clients). Also there are entries refer to media library for each post, such as attachment images or thumbnail images, witch is store in wp_postmeta table. Wordpress store them so the media attaches to posts or pages. If you want them to be exported too, you will need to use something like this :

 SELECT * FROM  `wp_postmeta` WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_backup_sizes',  '_wp_attachment_metadata',  '_thumbnail_id')

And then you can export them to wherever you want. It is all I know about media library stuff in Wordpress.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.