Where does the Media Library live in the database?

Select * from wp_posts where post_type="attachment";

Will return all the entries in the 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 are not sure if the entries already exist in your database, use the INSERT IGNORE statement instead of INSERT. (This is possible through exporting pan in phpMyAdmin or other MySQL clients).
Also, there are entries referring to the Media Library in each post, such as attachment images or thumbnail images, which are stored in the wp_postmeta table. WordPress stores them so the media “attaches” to posts or pages. If you want those 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.

Leave a Comment